簡體   English   中英

GridBagConstraints.gridheight無法正常工作

[英]GridBagConstraints.gridheight doesn't work correctly

我將JFrame實例的布局設置為new GridBagLayout() 我想將JTable添加到布局中,但是gridheight屬性似乎無法正常工作:

JFrame frame = new JFrame("GUI Test");

JTable tblTestTable = new JTable(new Object[][] { {"Bar", "Foo"} }, new Object[] { "Foo", "Bar" });

GridBagConstraints c = new GridBagConstraints() {{
    anchor = GridBagConstraints.WEST;
    insets = new Insets(2, 5, 2, 5);
    weightx = 1;
    weighty = 1;
}};

c.fill = GridBagConstraints.BOTH;
c.gridx = 2;
c.gridy = 0;
c.gridheight = 3; // Doesn't work
frame.add(tblTestTable, c);

frame.pack();
frame.setVisible(true);

這只是我的代碼的一小部分。 即使我將gridheight設置為3 ,布局管理器也將tblTestTable呈現為只有1行的元素。 我讀了一些有關gridheight不工作,如果gridx比我的大0 ,但我無法找到一個解決它。 已經有技巧來繞過這個嗎?

請確保使用剛構建的約束作為方法add()的參數,以便應用約束,例如

frame.add(tblTestTable, c);

(thx用戶432)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM