为什么Jtextarea没有出现在这段代码中? 我试着在jpanel中使用gridbaglayout添加一个Jtextarea。 框架可以正常打开,但没有Jtextarea。 我无法识别问题。请有人帮助我。为什么JTextArea没有出现在这段代码中?
import javax.swing.*;
import java.awt.*;
public class ServerTest{
//object declaration
JFrame f;
JPanel p;
JTextArea ta;
JTextField tf;
JButton b1,b2;
GridBagConstraints gbc;
//constructor
public ServerTest(){
//instantiation
f=new JFrame("Server");
p=new JPanel();
p.setBackground(Color.green);
ta=new JTextArea("Hello");
tf=new JTextField();
b1=new JButton("EMO");
b2=new JButton("VOICE");
gbc=new GridBagConstraints();
//end of instantiation
//frame task
f.setLayout(new FlowLayout());
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p.setLayout(new GridBagLayout());
gbc.gridx=0;
gbc.gridy=0;
gbc.gridwidth=3;
gbc.gridheight=5;
p.add(ta,gbc);
f.add(p);
f.pack();
f.setVisible(true);
//end of frame task
}
//Main method
public static void main(String []args){
ServerTest st = new ServerTest();
}
}
_but没有的JTextArea上it._但在这里我没有找不到像这样的问题。 – Satya
与@Satya发现的一样,代码似乎对我也很好。 – DevilsHnd
是的,你们都是对的..这是一个愚蠢的职位。 – SHB