What layout manager will do this?

2019-02-20 04:09发布

问题:

OY, not enough rep points to post an image...

____________________________________________________
|joes pizza                                         |
|          pizza type  toppings         ----------- |
|                                       |         | |
|          cheese       mushrooms       | 15.00   | |
|          veggie       extra cheese    |         | |
|          pepperoni    bacon           |         | |
|                                       ----------  |
|  _______________________________________________  |
|  |  calculate total                             | |
|  ------------------------------------------------ |
|___________________________________________________|

I'm supposed to build this for class, where the options in the middle are radio buttons and check boxes, and I have all the components in my panels in my frame. All I have left to do is actionListener and make it look like this. We are learning Layout Managers, and have been given five (FlowLayout, BorderLayout, GridLayout, BoxLayout, CardLayout, and GridBagLayout).

I can't seem to make any of them look like this, though. They either all end up in a line or in some crazy staggered representation, or crowded in from border to border. Any suggestions? In case my setup is getting in the way, I have joe's pizza in a label, pizza type in a pane, toppings in a pane, the textArea on the right, and finally a button. I'm not looking for an answer or the code to make it happen, just want to know what tools I should be using. If I can't figure out the tools, I'll ask another question or ask in the comments. Thanks for any suggestions.

Tony

回答1:

You can nest JPanels with different layouts. Here is one way to go about it. Picture should say it all.