views:

38

answers:

2

Let's say I would like to create a simple calculator. It consists of 3 fields. Text field to show result, field with checkboxes to select system and field with numbers.

What kind of component should I use for each element ? How can I position elements in my window ? How can I position elements inside component (ie checkboxes) ?

This is what I'm trying to achieve.

http://img28.imageshack.us/img28/7691/lab8c.jpg

+2  A: 
aioobe
A: 

First off, you start with determining, which LayoutManager you should use, to arrange your three fields. GridBagLayout will definitely do what you want, but is quite hard to program. You could try to get away with the simpler BorderLayout, which will make your application look odd, while resizing. You can use GroupLayout too. BoxLayout, GridLayout and FlowLayout are not what you want to use. Now you have a lot of options, to lay out you top elements.

Use a JTextField for the result. Use JCheckBox for the checkboxes, which you put insider a JPanel with an etched border (via JPanel.setBorder(BorderFactory.createEtchedBorder())) and a FlowLayout. Don't forget to put the checkboxes in a CheckboxGroup. Last but not least use a JPanel to group the JButtons for the, uhh, buttons. Use a GridLayout (5 rows, 4 columns) to arrange these buttons.

ablaeul