我有一个 JTextArea
我想根据列数和行数显示特定的文本行数组;但 getColumns 和 getRows 返回零。以下内容应该可以让您了解我想要实现的目标:
public class Frame extends JFrame implements ComponentListener {
...
this.textArea = new JTextArea();
this.textArea.setFocusable(false);
this.textArea.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20));
this.add(textArea, BorderLayout.CENTER);
this.editor = new Editor(new File("test"));
this.textArea.addComponentListener(this);
...
@Override
public void componentResized(ComponentEvent ce) {
this.editor.setHeight(this.textArea.getRows());
this.editor.setWidth(this.textArea.getColumns());
drawText();
}
为什么 getRows
和 getColumns
返回零?
最佳答案
使用这个构造函数
javax.swing.JTextArea.JTextArea(int rows, int columns)
编辑:
试试这个:
this.editor.setHeight(this.textArea.getHeight());
this.editor.setWidth(this.textArea.getWidth());
关于java - JTextArea getColumns、getRows 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29265933/