简体   繁体   中英

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? 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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