I'm creating a Swing GUI that uses a JToolbar. At the moment, I'm using a MigLayout and placing the toolbar inside of that. However, the result is that the toolbar does not span the whole width of the screen, but instead is only as long as it needs to be based on the buttons that I have added. This is my code concerning the initialization of the toolbar:
public class CoolButtons {
private JFrame frame;
public CoolButtons() {
initialize();
}
private JButton btnAddEmployee, btnSaveChanges, btnRemoveEmployee, btnHome;
Border matte = BorderFactory.createMatteBorder(0, 0, 3, 0, Color.BLACK);
private JSeparator separator;
private JToolBar toolBar;
private ImageIcon save, addNew, removeOne, deleteAll, home;
/**
* Initialize the contents of the frame.
*/
private void initialize() {
ToolTipManager.sharedInstance().setInitialDelay(200);
toolBar = new JToolBar("Tools", JToolBar.HORIZONTAL);
toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));
btnAddEmployee = new JButton();
//Configure the button... not important
toolBar.add(btnAddEmployee);
btnSaveChanges = new JButton();
//Configure the button... not important
toolBar.add(btnSaveChanges)
btnRemoveEmployee = new JButton();
//Configure the button... not important
toolBar.add(btnRemoveEmployee);
btnHome = new JButton();
//Configure the button... not important
toolBar.add(btnHome);
separator = new JSeparator();
//Configure the separator... not important
toolBar.add(separator);
frame.getContentPane().add(toolBar, "cell 0 0");
frame.pack();
}
When I run that code, I get this by default: Default
If I drag the JToolBar to the top of the screen, it expands to fill up the whole width of the screen like this: Expanded
My question is, how would I make the JToolBar fill up the whole width of the screen (as it does in the second picture) by default? As in, without having to drag it to the top of the screen.
I looked at this question "How to create Full Screen width jtoolbar", but it unfortunately didn't help. I tried the solution posted there, and nothing changed in my GUI.
Thank you for any advice or ideas :)