[英]Java Swing Gridlayout VERTICAL constraint
是否可以在Gridlayout Verticaly中添加組件? 我的意思是下一個高於前一個?
謝謝
不,沒有布局允許你從下往上垂直堆疊,至少我知道。 如果要垂直堆疊,可以使用帶單個列的GridLayout
或帶垂直軸的BoxLayout
。 通過嵌套面板和組合布局,您可以輕松獲得所需的內容,例如,垂直布局的面板都放在水平容器中。
BoxLayout和GridLayout等布局在您使用時從上到下顯示組件:
panel.add( someComponent );
但你總是可以使用:
panel.add(someComponent, 0);
在頂部插入組件。
雖然這個答案與網格布局無關,但我強烈建議使用JGoodies表單布局。 它非常靈活。 http://www.jgoodies.com/freeware/forms/index.html
/* 1 2 3 4 5 6 7 8 9*/
String col1 = "left:max(20dlu;pref), 3dlu, 70dlu, 15dlu,left:max(10dlu;pref),10dlu, 70dlu, 70dlu, 70dlu";
/* 1 2 3 4 5 6 7 8 */
String row1 = " p, 5dlu, p, 3dlu, p, 5dlu, p, 9dlu, ";
FormLayout layout = new FormLayout( col1, row1 + row2 + row3 + row4 + row5 + row6);
JPanel panel = new JPanel(layout);
panel.setBorder(Borders.DIALOG_BORDER);
// Fill the table with labels and components.
CellConstraints cc = new CellConstraints();
panel.add(createSeparator("Registration Information"), cc.xyw(1, 1, 7));
panel.add(new JLabel("Patient ID"), cc.xy(1, 3));
panel.add(pid, cc.xyw(3, 3, 1));
panel.add(new JLabel("Date and Time"), cc.xy(5, 3));
您可以手動編寫代碼以在設計的定義布局中的任何位置繪制每個組件,即對於col和行。 甚至垂直安排。 閱讀白皮書: http : //www.jgoodies.com/articles/forms.pdf
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.