• Post Reply Bookmark Topic Watch Topic
  • New Topic

BorderFactory to set positions  RSS feed

 
alejandro garcia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.LINE_START);
jPanelBoEx.setLayout(new BoxLayout(jPanelBoEx, 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.setBorder(BorderFactory.createEmptyBord 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..
Thanks in advance.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jchkbox1.setAlignmentX(.5f);
jTextField1.setAlignmentX(0);
jchkbox2.setAlignmentX(.5f);
jTextField2.setAlignmentX(0);
 
alejandro garcia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much!!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!