set 4 positions in BoxLayout

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aleplgr
    New Member
    • Aug 2007
    • 19

    set 4 positions in BoxLayout

    Hi! I hope someone could help:
    I defined a BoxLayout JPanel because I need to show in this order:
    a checkbox
    a textfield
    another checkbox
    another texfield

    and this works fine:

    JPanel jPanelBoEx = new JPanel();
    jPanelVars.add( jPanelBoEx, BorderLayout.LI NE_START);
    jPanelBoEx.setL ayout(new BoxLayout(jPane lBoEx, BoxLayout.PAGE_ AXIS));

    jPanelBoEx.add( jchkbox1);
    jPanelBoEx.add( jTextField1);
    jPanelBoEx.add( jchkbox2);
    jPanelBoEx.add( jTextField2);

    But I need not to show them in the center, they must be shifted some position to the right so I use this:

    jPanelBoEx.setB order(BorderFac tory.createEmpt yBord er(0, 160, 0, 0));
    To shift the four of them to the right, but I need the two textfields to be more to the right than the 2 checkboxes..

    But I can't find how to "move" the textfields to a different position than the checkboxes.. I can only position the 4 of them toguether, is there a way?

    Thanks in advance.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by aleplgr
    jPanelBoEx.add( jchkbox1);
    jPanelBoEx.add( jTextField1);
    jPanelBoEx.add( jchkbox2);
    jPanelBoEx.add( jTextField2);

    jPanelBoEx.setB order(BorderFac tory.createEmpt yBord er(0, 160, 0, 0));
    To shift the four of them to the right, but I need the two textfields to be more to the right than the 2 checkboxes..

    But I can't find how to "move" the textfields to a different position than the checkboxes.. I can only position the 4 of them toguether, is there a way?

    Thanks in advance.
    Put every object in its own JPanel, apply your border trick to each JPanel and
    add those four panels to your jPanelBoxEx.

    kind regards,

    Jos

    Comment

    • aleplgr
      New Member
      • Aug 2007
      • 19

      #3
      Originally posted by JosAH
      Put every object in its own JPanel, apply your border trick to each JPanel and
      add those four panels to your jPanelBoxEx.

      kind regards,

      Jos

      That will work! Thank you very much Jos

      Comment

      Working...