当你输入JTextArea时,它会自动调整大小以适应输入的文本。
然而,JTextField似乎不能做到这一点。这是一个演示问题的SSCCE:
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setLayout(new FlowLayout(FlowLayout.LEFT));
frame.add(new JTextArea("I resize as you type."));
frame.add(new JTextField("I don't."));
frame.setSize(200,100);
frame.setVisible(true);
}

我想知道是否有现成的方法可以让JTextField调整它的宽度。我希望我可以只使用JTextArea,但我只能接受一行输入。
发布于 2011-10-13 03:57:47
,但我只能接受一行输入
Single Line Text Area向您展示了如何做到这一点。相关代码为
textArea.getDocument().putProperty("filterNewlines", Boolean.TRUE);https://stackoverflow.com/questions/7745690
复制相似问题