• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

i need space between menus

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();

menubar.add(menu1);
menubar.add(menu2);
menubar.add(menu3);
menubar.add(menu4);
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just out of curiosity, why do you need space between them?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JMenu chartOptions = new JMenu("<html><font face=Georgia, Arial color=black><b>"
+ "Chart Options</b></font></html>");
chartOptions.setMargin(new Insets(0,50,0,50));
bar.add(chartOptions);

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.

Hope this helps.
 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic