I try to set a minimum width for my menu items, but it doesn't seem to work. Here is my function, which creates the items:
private JMenuItem newItem(String text, String iconPath) {
JMenuItem myMenuItem;
if (iconPath == null || iconPath.isEmpty()) {
myMenuItem = new JMenuItem(text);
}
else {
ImageIcon icon = new ImageIcon(iconPath);
myMenuItem = new JMenuItem(text, icon);
}
// this would work, but then setMaximumSize doesn't have any effect
// myMenuItem.setPreferredSize(new Dimension(250,20));
myMenuItem.setMinimumSize(new Dimension(250,20));
myMenuItem.setMaximumSize(new Dimension(350,20));
return myMenuItem;
}
What am I doing wrong?
PS. I'm using jdk1.6 on Windows XP, Servicepack 3 with the System Look&Feel