I am trying to use JTextArea.setText
in java to put me something up to the window. I wanted to get my screensize into textarea
, however, one of two .setText()
is not showing anything to the screen.
My code:
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);
}
}
Output:
width: 1920.0