先上我會告訴你它是如何:的Java Swing的GridBagLayout - 問題與放置兩個元素的面板
這是應該的(見下面的鏈接在我評論):
標籤必須打開並且TabPane必須在所有方向上用餘量填充屏幕的其餘部分。
這是使用GridBagLayout的鋪設出來的代碼:
// Layout --begin--
this.mainPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
// Layout:headLineLabel --begin--
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.ipadx = 0;
gbc.ipady = 0;
gbc.insets = new Insets(0, 10, 0, 0);
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
this.mainPanel.add(this.headLineLabel, gbc);
// Layout:headLineLabel --end--
// Layout:FestplattenreinigerGraphicalUserInterfaceTabbedPane --begin--
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.fill = GridBagConstraints.BOTH;
gbc.ipadx = 0;
gbc.ipady = 0;
gbc.insets = new Insets(10, 10, 10, 10);
gbc.anchor = GridBagConstraints.CENTER;
this.mainPanel.add(new FestplattenreinigerGraphicalUserInterfaceTabbedPane(), gbc);
// Layout:FestplattenreinigerGraphicalUserInterfaceTabbedPane --end--
// Layout --end--
事情你需要知道:
- FestplattenreinigerGraphicalUserInterfaceTabbedPane延伸JTabbedPane的。
- 我試圖指定所有約束(即使使用它們的默認值)來練習。
- 如果我推薦了錨,佈局仍然如此。
這件事有什麼不對?
THX非常! (對不起,我無法直接發佈圖片+只有1個鏈接,因爲我是新的.-)
它應該如何:http://img832.imageshack.us/img832/6905/howitshouldbe.jpg – JavaHater 2010-11-28 16:18:42