简体   繁体   中英

How to setup this GUI with Java Swing?

I got a GUI to make and I've tried so many ways, but I can't seem to build it correctly, I always get the layouts wrong and my application gets all messed up. I just want some help on how to build something close to the GUI in the image, except the image part, that isn't necessary. Doesn't need to be exactly like it, I just need some ideas of what layouts to use and how. Thanks 1]

As with all problems, start by breaking it down into manageable chunks.

Associate the various UI elements together into groups of "functionality" and separate them into separate components - this way you can focus on the individual layout requirements for each section

整体布局

From this, I would then focus on breaking down each group into individual components and focus on there core functionality

选件

So this is pretty basic, I'd use a GridBagLayout because it would allow me to anchor the components to the top position of the container. You could also use the VerticalLayout from SwingX

清单

So, there are a number of possibilities, but, because it would be simple to do, I'd use a GridBagLayout , as it would allow me to provide more space for the two lists

个人资料

A little more complicated, but still, GridBagLayout , as it allows more control over providing space to individual components

播放栏

And, GridBagLayout for all the reasons highlighted above.

Finally...

Bringing it all together...

I'd probably start by placing the green, blue and yellow sections into a separate container (using, surprise, a GridBaglayout , as it allows for components to expand cells) and then combine it with the purple section onto a container using a BorderLayout

I would recommend that you take the time to look at Laying Out Components Within a Container and try somethings and see what does and doesn't work.

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