我正在使用网格包布局来创建如下所示的布局:
但我所拥有的是:
为什么会这样?我已经指定了左对齐并占据了所有水平空间,但我仍然得到了这个。这是我的代码:
public DepotView()
{
setSize(FRAME_WIDTH,FRAME_HEIGHT);
setLocationRelativeTo ( null );
getContentPane ().setLayout ( new GridBagLayout());
JPanel workerPanel = createTextAreaPanel("Processing: ",workerArea);
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 2;
c.gridheight = 1;
c.weightx = 1;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_START;
getContentPane().add ( workerPanel );
JPanel customerPanel = createTextAreaPanel("Customers: ",textArea);
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.5;
c.insets = new Insets(5,5,5,5);
getContentPane().add ( customerPanel );
JPanel depotPanel = createTextAreaPanel("Depot: ",depotArea);
c = new GridBagConstraints();
c.gridx = 1;
c.gridy = 1;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.5;
c.insets = new Insets(5,5,5,5);
getContentPane().add ( depotPanel );
//pack();
setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );