2

Is it possible to set height of JMenuBar, JMenu and JMenuItem using UIManager once for all menus?

I am currently using:

setPreferredSize(new Dimension(100, 25));

But I feel it's not the best way.

Edward Ruchevits
  • 6,411
  • 12
  • 51
  • 86
  • 1
    Why do you want menus to appear bigger? Do you want the font to be bigger too? Or do you just want some insets? In the latter case, rather set an empty border on the various elements to achieve the desired result. – Guillaume Polet May 08 '13 at 21:51
  • 1
    About the only solution that would be global would be to replace the UI delegates for these components. That's a lot of extra work... – MadProgrammer May 08 '13 at 21:53

2 Answers2

5

The best way is to let system handle the width and height (a call to super should give you the correct width and height which will display the full text contents)

Although if you want explicitly setting the width to 100 and height to 25, setPreferredSize() is one way.. Another way is to use Box Layout

menuBar.add(Box.createRigidArea(new Dimension(100,25)));
Mady
  • 653
  • 4
  • 11
0

The answer by Mady will squeeze all your JMenus(if that's what you added on the JMenuBar) to the extreme left corner and display your empty Box on the menubar.

This works well:

menubar.setPreferredSize(new Dimension(width,height));
Eric Aya
  • 69,473
  • 35
  • 181
  • 253