My menus are attached to each other, and displayed horizontally, i need space between them . Here is my code: I used addSeparator(), but I think that is to create space between menuitems and not between menus .... //Create the menu bar. menubar = new JMenuBar(); //Build the first menu. menu1 = new JMenu("Options"); menu1.setBackground(color3); menu1.addSeparator(); menu2 = new JMenu("Help"); menu2.setBackground(color3); menu2.addSeparator(); menu3 = new JMenu("Edit"); menu3.setBackground(color3); menu3.addSeparator(); menu4 = new JMenu("Quit"); menu4.setBackground(color3); menu4.addSeparator();
Hi sarim, I never found any documentation on this and worked on it for several days until I just decided to try something out of desparation and it worked. Just add an empty JPanel to the menu bar and it will add space. For example:
Hope this helps, Michael Morris
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
You can add the insets to the bar itself, but then it makes the menu bar larger. Insets are same as GridBag Layout. First Integer is number of pixels from the top, the second is from the left, the third is from the bottom, and the fourth from the right.
Hi Greg, and welcome to JavaRanch! It's always good to see another 2 G Greg around here!
This particular question was asked over ten years ago, so the OP has most likely gone on to other problems by now. Stick around though! There are plenty of questions of more recent vintage that need answering.