I'm trying to add a vertical JSeparator in my menu. But it puts margins between my MenuItems. I want my items to stay left instead of left - center - right.
How it looks:
What I want:
JMenu settings = new JMenu("Settings");
image = ImageIO.read(new File(Constants.IMAGES_DIR + File.separator + "settings.png"));
settings.setHorizontalTextPosition(SwingConstants.CENTER);
settings.setVerticalTextPosition(SwingConstants.BOTTOM);
settings.setIcon(new ImageIcon(image));
add(settings);
JMenu build = new JMenu("Builder");
image = ImageIO.read(new File(Constants.IMAGES_DIR + File.separator + "build.png"));
build.setHorizontalTextPosition(SwingConstants.CENTER);
build.setVerticalTextPosition(SwingConstants.BOTTOM);
build.setIcon(new ImageIcon(image));
add(build);
add(new JSeparator(JSeparator.VERTICAL));
JMenu help = new JMenu("Help");
image = ImageIO.read(new File(Constants.IMAGES_DIR + File.separator + "help.png"));
help.setHorizontalTextPosition(SwingConstants.CENTER);
help.setVerticalTextPosition(SwingConstants.BOTTOM);
help.setIcon(new ImageIcon(image));
add(help);
hope you understand what I want.
I suggest doing this by using JToolBar instead of JMenuBar. But in case you must/should/like to do it using JMenuBar here goes an example:
In simple words - you can use MigLayout and set "growy" on your JSeparators. There are many other solutions for this (using different layout).