如何在swing中使用GridLayout使我的列具有不同的大小? [英] How can I make my columns different sizes using GridLayout in swing?
问题描述
我正在使用GridLayout,我的代码如下:
I'm using a GridLayout and my code is as follows:
int changingVar = 1;
JPanel panel = new JPanel(new GridLayout(changingVar, 2));
panel.add(new JButton("BUTTON1"));
panel.add(new JButton("BUTTON2"));
这看起来像是:
___________________________________________
| [ BUTTON1 ] [ BUTTON2 ] |
___________________________________________
这是两个大小均匀的列。我想这样做:
which is two evenly sized columns. I would like to make it like this:
___________________________________________
| [ BUTTON1 ] [ BUTTON2 ] |
___________________________________________
其中一列占用的面板空间多于另一列。如何使用gridlayout执行此操作?我并不反对使用其他布局,只要我可以有两个不同大小的不同数量的行和列。
in which one column takes up more of the panel space then the other. How do I do this with gridlayout? I am not oppose to using another layout as long as I can have a varying amount of rows and columns that are two different sizes.
谢谢
推荐答案
如果你想要这个效果那么你需要利用GridBagLayout。
If you want this effect then you need to utilize the GridBagLayout.
http://download.oracle.com/javase/tutorial/uiswing/layout/gridbag.html
玩得开心= P
编辑:
您可以通过使用FlowLayout和GridLayout的混合来解决问题,以获得类似的效果。但是,当您的布局复杂性变得更大时,此解决方案将变得非常繁琐和混乱。
You can work around the problem by employing a mixture of FlowLayout and GridLayout to get a similar effect. However, this solution will become extremely tedious and messy as your layout complexities become bigger.
这篇关于如何在swing中使用GridLayout使我的列具有不同的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!