[英]Resize JTextArea
我想做的事情确实很简单,但是我找不到解决方案。
我有一个JTextArea添加到JPanel,并且我想在调整JPanel大小时调整JTexArea的大小。 当我调整JFrame的大小时,我能够调整JPanel的大小,但是对于JTextArea来说,它似乎无法以相同的方式工作。 有任何想法吗? 这是我使用的代码。
public HelpPanel( Map<ComponentType, String> compMap ) {
super();
this.componentMap = compMap;
compDescription = new JTextArea();
setSize(300, 300);
JScrollPane scroll = new JScrollPane(compDescription);
add( scroll );
compDescription.setPreferredSize(new Dimension(getSize()));
compDescription.setLineWrap(true); //Wrap the text when it reaches the end of the TextArea.
compDescription.setWrapStyleWord(true); //Wrap at every word rather than every letter.
compDescription.setEditable(false); //Text cannot be edited.
displayDescription();
}
更改super();
super(new BorderLayout());
。
JPanel默认使用FlowLayout,它不会尝试强制其组件的大小来填充空间。 通过切换到BorderLayout,中心组件(滚动窗格)将被强制匹配面板的大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.