简体   繁体   中英

Adding JTextArea to JFrame not showing

I tried searching around and cant seem to find why my JTextArea isn't showing, I have a separate class to make a GUI but when I declare a new GUI in that class, the GUI pops up with the correct title and size but no TextArea.

    import java.awt.Container;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextArea;     

    public class BaseballPlayerGUI extends JFrame {

        JTextArea arear = new JTextArea();

        public BaseballPlayerGUI() {
                this.setSize(500,500);
                this.setTitle("Baseball Players");
                this.setVisible(true);
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
                arear.setText("Why wont this show in TextArea!");
        }
   }

I tried searching around and cant seem to find why my JTextArea isn't showing,

You didn't add the text area to the frame:

this.add(arear);
this.setSize(500,500);

Also, usually you add a text area to a scroll pane so you would probably use:

this.add(new JScrollPane(arear) );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM