简体   繁体   English

使用GroupLayout对齐

[英]Alignment using GroupLayout

I am having trouble aligning my components in my panel. 我在面板上对齐组件时遇到问题。

Currently, it looks like this: 当前,它看起来像这样:

|system...power| |系统...电源|

|fuel...................| |燃料......... |

|(slider)..............| |(滑块).............. |

|go.....................| |去..................... |

I want it to look like this (with fuel, slider, and go all horizontally aligned in the middle): 我希望它看起来像这样(带有燃料,滑块,并在中间全部水平对齐):

|system...power| |系统...电源|

|..........fuel.........| | ..........燃油......... |

|.......(slider)...... | | .......(滑块)...... |

|.......... go......... | | ..........去......... |

(Forgive me for the confusing layout of these examples, I do not have the reputation to post images) (请原谅我这些示例的布局混乱,我没有发布图像的声誉)

The code corresponding to the layout is this:] 对应于布局的代码是这样的:]

layout.setVerticalGroup(
            layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup()
                    .addComponent(systems_box)
                    .addComponent(fuelamount)   
                    .addComponent(power_box))
            .addComponent(fuel_input)
            .addComponent(gobutton)     
    );

    layout.setHorizontalGroup(
            layout.createSequentialGroup()
            .addComponent(systems_box)
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
                    .addComponent(fuelamount)
                    .addComponent(fuel_input)
                    .addComponent(gobutton))
            .addComponent(power_box)
    );

I am wondering if it is possible to make it how I want it to look using GroupLayout? 我想知道是否可以使用GroupLayout使它看起来像我的样子? I also don't want to just have the system and power on each end of the fuel component, as it is a fairly long component. 我也不想在燃料组件的每个末端都安装系统和电源,因为它是一个相当长的组件。

Thanks in advance :) 提前致谢 :)

To overcome this, I ended up creating an upper and lower panel which were aligned using GroupLayout and then used GroupLayout again to align their corresponding components. 为了克服这个问题,我最终创建了一个上下面板,并使用GroupLayout对其进行了对齐,然后再次使用GroupLayout来对齐其相应的组件。 Although it may be a bit unnecessary to do it this way, I'm glad I managed to work out how it is possible using only GroupLayout. 尽管这样做可能没有必要,但我很高兴能够设法仅使用GroupLayout来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM