Link to home
Start Free TrialLog in
Avatar of StevenZhang
StevenZhang

asked on

How to change item position in a Dialog box.

There is dialog box which has two items as following:
  AAA:  AAA ComboBox
  BBB:   BBB  ComboBox

I want to change it in the dialog as the following:
 AAA:  AAA ComboBox     BBB:   BBB  ComboBox

Could you help me to reslove it? My codes is as following:

final PanelBean centerPanel = new PanelBean(new SpringLayout());

final LabelBean AAALabel = new LabelBean(AAA_TEXT);
AAALabel.setHorizontalAlignment(LabelBean.RIGHT);
centerPanel.add(AAALabel);

....
AAACombo = new PreferencableComboBoxBean( studentAAAStructs, AAA_STUDENT_ETC_COMBOBOX_PREF_KEY_STRING, "0" );

final PanelBean AAAFlowPanel = new PanelBean( new FlowLayout(FlowLayout.LEFT, 0, 0) );
Dimension prefSize = AAACombo.getPreferredSize();
AAACombo.setPreferredSize( new Dimension(185, prefSize.height) );
AAAFlowPanel.add( AAACombo );
centerPanel.add( AAAFlowPanel );


final LabelBean BBBLabel = new LabelBean(BBB_TEXT);
BBBLabel.setHorizontalAlignment(LabelBean.RIGHT);
centerPanel.add(BBBLabel);
.....
BBBCombo = new PreferencableComboBoxBean( BBBTypes, BBB_ETC_COMBOBOX_PREF_KEY_STRING, "0" );
final PanelBean BBBFlowPanel = new PanelBean( new FlowLayout(FlowLayout.LEFT, 0, 0) );
Dimension BBBPrefSize = BBBCombo.getPreferredSize();
BBBCombo.setPreferredSize( new Dimension(185, BBBPrefSize.height) );
BBBFlowPanel.add( BBBCombo );
centerPanel.add( BBBFlowPanel );


Thanks.
Avatar of sciuriware
sciuriware

Could you forget about SpringLayout and use a HorizontalBox,
with 'glue' and 'struts' you can position those 6 components as fine as you want:

    Box panel = Box.createHorizontalBox();
.......
    panel.add(AAAlabel);
    panel.add(Box.createHorizontalStrut(12)); // 12 is just a guess.
    panel.add(AAAfield); // What ever that is ...
    panel.add(Box.createHorizontalStrut(12));
    panel.add(AAAcomboBox);
    panel.add(Box.createHorizontalGlue); // variable distance to the 2nd group, depends on the total space.
.....
and so on.

;JOOP!
Avatar of StevenZhang

ASKER

I used SpringLayout to resolve it by myself. Anyway, Thanks.
The soultion is to re-arrange the panels, then adjust the parm of the following function.

SpringUtilities.makeCompactGrid(centerPanel,                                          2, 4,
                  5, 5,
                  5, 5);

Anyway, Thanks.
ASKER CERTIFIED SOLUTION
Avatar of GhostMod
GhostMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial