package UI;
import java.awt.*;
import javax.swing.*;
public class GridBagLayout1
{
public Component crateComponent()
{
JPanel pane=new JPanel(new GridBagLayout());
GridBagConstraints gg=new GridBagConstraints();
JLabel label=new JLabel("Possibilities");
JLabel label1=new JLabel("Actualities");
JTextArea txtArea=new JTextArea(3,3);
JTextArea txtArea1=new JTextArea(3,2);
JTextField txtField=new JTextField("单行文本");
JButton button=new JButton("Clear");
gg.fill=GridBagConstraints.NONE;
gg.gridx=0;
gg.gridy=0;
gg.gridwidth=3;
gg.gridheight=1;
gg.weightx=2;
pane.add(label,gg);
gg.fill=GridBagConstraints.NONE;
gg.gridx=1;
gg.gridy=0;
gg.gridwidth=3;
gg.gridheight=1;
gg.weightx=2;
pane.add(label1,gg);
gg.fill=GridBagConstraints.NONE;
gg.gridx=0;
gg.gridy=1;
gg.gridwidth=3;
gg.gridheight=4;
gg.weighty=10;
pane.add(txtArea,gg);
gg.fill=GridBagConstraints.NONE;
gg.gridx=1;
gg.gridy=1;
gg.gridwidth=2;
gg.gridheight=4;
gg.weighty=10;
pane.add(txtArea1,gg);
gg.fill=GridBagConstraints.NONE;
gg.gridx=0;
gg.gridy=2;
gg.gridwidth=3;
gg.gridheight=1;
pane.add(txtField,gg);
gg.fill=GridBagConstraints.NONE;
gg.gridx=1;
gg.gridy=2;
gg.gridwidth=2;
gg.gridheight=1;
pane.add(button,gg);
return pane;
}
public static void main(String[] args)
{
JFrame frame=new JFrame("容器的位置");
GridBagLayout1 aa=new GridBagLayout1();
frame.getContentPane().add(aa.crateComponent());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
不知道哪个地方出错了,那些个label和哪个文本框都重叠了...和我想的太不一样了...不知道那位能帮小弟解决这个问题