简体   繁体   English

线路完成后,如何自动将文本区域文本转到下一行?

[英]How to make text area text automatically go to the next line when line is finished?

This is my code for text field. 这是我的文本字段代码。 It is not changing the line when the line ends, but continues to go on, making the frame look weird. 当线条结束时它不会改变线条,但是继续继续,使框架看起来很奇怪。

I tried to use a scroll pane, but it did not help me. 我试图使用滚动窗格,但它没有帮助我。

JTextArea TextArea = new JTextArea(7,10);
gridConstraints.gridx = 0;
gridConstraints.gridy = 0;
TextPanel.add(TextArea, gridConstraints);
TextArea.setEditable(true); 

Without line & word wrapping, the size of a JTextArea will grow beyond its original size. 如果没有换行和换行, JTextArea的大小将超出其原始大小。 You could call: 你可以打电话:

textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);

Side notes: 附注:

  • JTextArea are typically placed in JScollPane containers to facilitate scrolling. JTextArea通常放在JScollPane容器中以方便滚动。
  • Java naming conventions indicate that variables start with a lowercase letter, making TextArea textArea Java命名约定表明变量以小写字母开头,使TextArea textArea

I can provide a solution if you are using SceneBuilder. 如果您使用的是SceneBuilder,我可以提供解决方案。

Select the TextArea-element from the hierarchy-tree, go to "Inspector", select the tab "Properties" and activate "Wrap Text". 从层次树中选择TextArea元素,转到“Inspector”,选择“属性”选项卡并激活“自动换行”。

Then, every text within the TextArrea-element will have a return at the end of the line. 然后,TextArrea元素中的每个文本都将在该行的末尾返回。

Screenshot 截图

Cheers 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM