how to visualize console java in JFrame/JPanel

前端 未结 2 949
情书的邮戳
情书的邮戳 2020-12-06 17:33

I made a Java program using Swing libraries. Now I would like to redirect my console outputs into a JFrame or JPanel.

2条回答
  •  囚心锁ツ
    2020-12-06 18:21

    Once you have your JFrame or JPanel, add a text field to it.

    JTextArea is a good choice, because it's multiple lines. Once it is added, you can .append('text'); to it instead of writing the System.out.print();

    JFrame jFrame = new JFrame();
    
    JTextArea jTextArea = new JTextArea();
    jTextArea.append( "Hello World." );
    
    jFrame.add( jTextArea );
    

提交回复
热议问题