This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

i need space between menus  RSS feed

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • 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
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!