這裏是我的當前設置:如何使用絕對定位將組件添加到JComponent中?
private JComponent upperContent = new GeneralContent();
private JComponent lowerContent = new GeneralContent();
// GeneralContent extends JComponent
jframe.setLayout(new GridLayout(2, 0));
upperContent.setLayout(null);
lowerContent.setLayout(new GridBagLayout());
jframe.add(upperContent);
jframe.add(lowerContent)
lowerContent的所有部件都如預期,而upperContent沒有顯示我是通過使用下面的代碼添加到它的組件顯示:
JLabel label=new JLabel();
upperContent.add(label);
label.setLocation(15,15);
我也使用label.repaint(); & upperContent.revalidate()兩者都不起作用
使用佈局(+佈局填充和邊框),以實現所需的效果。 'null'佈局會回來咬你後面。 – 2012-02-10 00:46:55