简体   繁体   English

将JTextArea添加到JFrame中不显示

[英]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. 我尝试四处搜索,但似乎无法找到为什么我的JTextArea没有显示的原因,我有一个单独的类来制作GUI,但是当我在该类中声明一个新的GUI时,该GUI弹出并带有正确的标题和大小,但没有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, 我尝试四处搜寻,但似乎找不到为什么我的JTextArea无法显示,

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) );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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