setPreferredSize(new Dimension(...));
works on menu items. setMinimumSize
does not work though; it does not seem to be honored by the menu layout manager, so if you want to set a minimum that may be overridden by having larger content, or you want to set a minimum or preferred width without changing the height, you must override getPreferredSize()
in a subclass. E.g.,
menuOne.add(new JMenuItem("1") {
@Override
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
d.width = Math.max(d.width, 400); // set minimums
d.height = Math.max(d.height, 300);
return d;
}
});