• Post Reply Bookmark Topic Watch Topic
  • New Topic

Vertical JMenuBar with fixed size JMenu(s) with centering content  RSS feed

 
Petra Cervinkova
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,

this is my code for GUI:

Looks like:


I have problem with centering text and icon in JMenu. Also I would like to have fixed height of JMenu (not affected by resizing main window). The width is now 100 % of JMenuBar, that is ok.

Any ideas, please ?
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, have you gone through the Oracle tutorial How to Use Menus? The tutorial is the first place I go to when I want to learn how to use a Java feature.
 
Petra Cervinkova
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I read it. There is only one example for vertical JMenuBar and no care about fixed size and content centering.
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JMenuBar was not designed to be displayed vertically. That is why there is a special method setJMenuBar(...) to add the JMenuBar to the frame.

If you did try to add it vertically then you might try adding it to the LINE_START of the BorderLayout, not the center. This way the width should be constrained by the menus added to the menu bar.

You also would not want to use a GridLayout since the vertical height will change as the frame size changes.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!