Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
660 views
in Technique[技术] by (71.8m points)

swing - Choosing the layout managers and number of panels for Java GUI

I would appreciate, If anyone here is kind enough to recommend me what are the layout managers to choose and how to separate the attached GUI into Jpanels.

enter image description here

Thanks so much in advance.

What I have tried so far:

Jframe - BorderLayout Map (the grid and clear button from another class extending jpanel) - so I have put it in jframe.CENTER

the buttons to the right: jframe.EAST I put them in a jpanel in a gridlayout (but I cannot get the spacing between the components)

buttons at the bottom: jframe.SOUTH I put them in a jpanel in a gridlayout (but I cannot get the spacing between the components)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When trying to determine what layout(s) you should use, you should start by trying to determine areas of responsibility...

For example...

enter image description here

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

enter image description here

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

enter image description here

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

For this panel...

enter image description here

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

enter image description here

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

enter image description here

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...