问题描述
我很感激,如果有人在这里建议我选择
的布局经理以及如何将附加的GUI分成Jpanels。
I would appreciate, If anyone here is kind enough to recommend me what are the layout managers to chooseand how to separate the attached GUI into Jpanels.
非常感谢提前。
到目前为止我尝试了什么:
What I have tried so far:
Jframe - BorderLayout
地图(从另一个类扩展jpanel的网格和清除按钮) - 所以我把它放在jframe.CENTER
Jframe - BorderLayoutMap (the grid and clear button from another class extending jpanel) - so I have put it in jframe.CENTER
右边的按钮:jframe.EAST
我放了它们位于gridlayout的jpanel中(但是我无法获得组件之间的间距)
the buttons to the right: jframe.EASTI put them in a jpanel in a gridlayout (but I cannot get the spacing between the components)
底部的按钮:jframe.SOUTH
我把它们放在一个在gridlayout中的jpanel(但是我无法获得组件之间的间距)
buttons at the bottom: jframe.SOUTHI put them in a jpanel in a gridlayout (but I cannot get the spacing between the components)
推荐答案
当试图确定你的布局时应该使用,你应该首先尝试确定责任范围...
When trying to determine what layout(s) you should use, you should start by trying to determine areas of responsibility...
例如......
根据您的需求,我可以从 GridBagLayout
开始。这可能看起来很复杂,但是如果你将UI分解成单独的组件,专注于他们的个人需求,它应该变得更简单...
Based on your needs, I might start with a GridBagLayout
. This might seem complex, but if you break the UI down into seperate components, focusing on their individual needs, it should become simpler...
对于左边的面板...
For the panel on the left...
我很想使用 GridBagLayout
,因为它允许组件使用那些首选大小,但仍然允许你要设置一个类似网格的网格...
I would be temptered to use a GridBagLayout
, simply because it allows the components to use there preferred sizes, but still allows you to set up a grid like pattern...
对于箭头按钮......
For the arrow buttons...
这变得有点复杂,但我会使用 GridLayout(2,3)
(2行,3列)。这将需要在顶行的第一和第三位置添加填充面板,但仍然保持按钮的大小相等...
This becomes a little more complicated, but I would use a GridLayout(2, 3)
(2 rows, 3 columns). This will require to add a filler panel at the first and third position along the top row, but still maintain the buttons at a equal size...
对于此面板。 ..
我很想使用 GridBagLayout
,因为它可以让你跨越行甚至再分成几行两个单独的面板,左边的控件位于 GridLayout(2,1)
中,右边的控件位于 BorderLayout
根据需要......
I would be tempted to either use a GridBagLayout
, because it will allow you to span the rows or even split it again into two separate panels, with the controls on the left in a GridLayout(2, 1)
and the control on the right in something like a BorderLayout
as required...
对于进度面板......
For "progress" panel...
我很想使用。 .. 的GridBagLayout
。主要是因为它可以让你为进度条提供更多的权重,然后是标签。
I would be tempted to use...GridBagLayout
. Mostly because it would allow you to provide more weight to the progress bars then the labels.
对于主面板......
For the main panel...
我可能想要在另一个面板上使用 BorderLayout
和 Clear Map
,允许它保持它的首选大小,在 NORTH
位置和 CENTER
中的地图面板,甚至是 GridBagLayout
取决于invidual组件是什么......
I would probably be tempted to either use a BorderLayout
, with the Clear Map
on another panel of it's own, allowing it maintain it's preferred size, in the NORTH
position and the map panel in the CENTER
or even a GridBagLayout
depending on what the invidual components are...
这篇关于选择Java GUI的布局管理器和面板数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!