| Author |
GroupLayout radio button alignment
|
Jerry Goldsmith
Ranch Hand
Joined: Nov 29, 2006
Posts: 53
|
|
Hello, I am trying to create a simple frame with rows of radio buttons using GroupLayout. I have it working except I cannot get the rows of buttons to align along the left hand side. I have tried using the GroupLayout.LEADING argument to no avail. What I would like to see should look like this: A B 1 2 3 4 5 6 RED BLUE GREEN What I am actually getting looks like this: A B 1 2 3 4 5 6 RED BLUE GREEN Is anyone familiar with GroupLayout? It seems like each of these rows should belong to one parallel group. Here is my code: public void setup() { layout.setAutocreateGaps(true); layout.setAutocreateContainerGaps(true); for (int i = 0; i < numRows; i++) { numBtns[i] = values[i].length; rBtns = new JRadioButton[numRows][numBtns[i]]; for (int j = 0; j < numBtns[i]; j++) { rBtns[i][j] = new JRadioButton(values[i][j]); rBtns[i][j].setSelected(false); rBtns[i][j].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.equals("Selected")){; System.out.println("Selected"); } } }); switch (i){ case 0: SeqGroup0.add(rBtns[i][j]); ParaGroup0.add(rBtns[i][j]); case 1: SeqGroup1.add(rBtns[i][j]); ParaGroup1.add(rBtns[i][j]); case 2: SeqGroup2.add(rBtns[i][j]); ParaGroup2.add(rBtns[i][j]); } } } getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.LEADING) .add(SeqGroup0) .add(SeqGroup1) .add(SeqGroup2) ); layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.BASELINE) .add(layout.createSequentialGroup() .add(ParaGroup0) .add(ParaGroup1) .add(ParaGroup2) ) ); pack(); } Thanks.
|
 |
Jerry Goldsmith
Ranch Hand
Joined: Nov 29, 2006
Posts: 53
|
|
Sorry. I haven't got the hang of the use of HTML tags in postings yet. I will use periods to represent spaces. What I would like to see is this: A B 1 2 3 4 5 RED BLUE GREEN What I am actually seeing is this: A B .....1 2 3 4 5 ...............RED BLUE GREEN TIA
|
 |
Jerry Goldsmith
Ranch Hand
Joined: Nov 29, 2006
Posts: 53
|
|
Got it! I forgot to add break statements to my switch construct:
|
 |
 |
|
|
subject: GroupLayout radio button alignment
|
|
|