Edward Ruchevits
Edward Ruchevits

Reputation: 6696

Height of JMenuBar, JMenu and JMenuItem

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.

Upvotes: 2

Views: 14759

Answers (2)

Bolo Kevin
Bolo Kevin

Reputation: 1

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));

Upvotes: 0

Mady
Mady

Reputation: 653

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)));

Upvotes: 5

Related Questions