JTextArea.setText not visible
我试图在Java中使用
我的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public class SimpleFrame { public static void main(String[] args) { JFrame frame = new JFrame("Demo"); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); double hi = d.getHeight(); double wi = d.getWidth(); JTextArea area = new JTextArea(10, 10); area.setEditable(false); area.setText("height:" + hi); area.setText("width:" + wi); frame.setSize(400, 400); frame.add(area); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setLocationRelativeTo(null); } } |
输出:
1 | width: 1920.0 |
您需要用
public void append(String str) :
Appends the given text to the end of the document.
public void setText(String t) :
Sets the text of this TextComponent to the specified text.