• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic