Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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: 21892
36
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: 2703
10
  • 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.
 
Hang a left on main. Then read this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!