[英]Adding JTextArea to JFrame not showing
我嘗試四處搜索,但似乎無法找到為什么我的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!");
}
}
我嘗試四處搜尋,但似乎找不到為什么我的JTextArea無法顯示,
您沒有將文本區域添加到框架:
this.add(arear);
this.setSize(500,500);
另外,通常您將文本區域添加到滾動窗格中,因此您可能會使用:
this.add(new JScrollPane(arear) );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.