i have a toolBar, and i need to put a series of jbuttons and jlabels to the left of the screen, but one of the buttons to the right. I can't make the last one move to the right.
this.panelControl=new JToolBar();
setLayout(new FlowLayout(FlowLayout.LEFT)); //i use it to move them to the left, probably wrong
panelControl.add(load);
panelControl.addSeparator();
panelControl.add(laws);
panelControl.addSeparator();
panelControl.add(play);
panelControl.add(stop);
panelControl.add(labelSteps);
panelControl.add(steps);
panelControl.add(labelTime);
panelControl.add(time);
panelControl.add(exit); // i need this to be in the right side, but i can't
this.add(panelControl);
Thank you very much in advance.
Use the JToolBar's own layout, but add a horizontal glue between the last two buttons. This will space things out for you. For example:
As per VGR's comment:
and he's right. So change this:
to this:
so that the separation persists even if the toolbar is placed in a vertical position
Also note that if you need to limit the size of the JTextField, you could set its maximal size to its preferred size, e.g.,