如何将jpanel添加到GridLayout的特定单元格 [英] How to add jpanel to a specific cell of GridLayout
问题描述
在下面的代码中,我创建了一个具有3行3列的GridLayot,我想要做的是,将jpanel_1添加到 Gridlayout的特定单元格,让我们在网格单元格编号(2,3)中说.
in the below code, i created a GridLayot with 3 rows and 3 columns, what i want to do is,,to add jpanel_1 into a specifc cell of the Gridlayout, lets say in the grid cell number (2,3).
代码:
private void setUpGUI2() {
// TODO Auto-generated method stub
jFrame_2 = new JFrame("Border Demo");
GridLayout gridLayOut = new GridLayout(3,3);
jFrame_2.setLayout(gridLayOut);
jPanel_1 = new JPanel(new BorderLayout());
jPanel_2 = new JPanel(new BorderLayout());
jPanel_1.setBorder(BorderFactory.createTitledBorder("title"));
//jPanel_1.setBounds(30, 100, 110, 300);
jPanel_1.add(jLabel_Hello, BorderLayout.EAST);
jPanel_2.setBorder(BorderFactory.createLoweredBevelBorder());
//jPanel_2.setBounds(20, 50, 120, 80);
jPanel_2.add(jLabel_Hello, BorderLayout.SOUTH);
//jFrame_2.setBounds(0, 0, 600, 600);
jFrame_2.add(jPanel_1);//how to add jpanel_1 to a specific cell of Gridlayout defined above
//jPanel_1.add(jPanel_2);
jFrame_2.add(jPanel_2);
jFrame_2.pack();
jFrame_2.setVisible(true);
}
推荐答案
我认为没有机会.您需要一个一个地添加它们.
frame.add(...); frame.add(...);
我不清楚您想要的结果是什么,但是仅在两个面板中使用GridLayout(3, 3)
与使用GridLayout(0, 2)
相同.
P.S.查看GridBagLayout-它对您可能更有用.
I think there is no chance. You need to add them one by one.
frame.add(...); frame.add(...);
I don't clearly understand what you want as result, but using GridLayout(3, 3)
with only 2 panels is the same as use GridLayout(0, 2)
.
P.S. Check out GridBagLayout - it can be more useful for you.
这篇关于如何将jpanel添加到GridLayout的特定单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!