Swing: placing JMenuItem without LayoutManager

Hi,
I’m really stuck with this: I would like to place JMenuiItems without LayoutManager. My approach was:

JMenuItem jMenuItemZO = new JMenuItem();
ImageIcon image1 = new ImageIcon(“d:\vec25shp\zoomout_up.png”);
jMenuItemZO.setIcon(image1);

getContentPane().setLayout(null);
jMenuItemZO.setBounds(0, 0, 20, 20);
getContentPane.add(jMenuItemZO);

However, this doesn’t seem to work properly: the icon gets disrupted, there’s a gap of some 5 pixels on the left border of the icons and it’s not displayed fully.

So I really wonder how I could place this component correctly.

thanks,
Crest

(Disclaimer - I’m not a GUI developer)

Is the icon being cut off because you’re setting the bounds of the component too small?

Shouldn’t you be adding the JMenuItem to a JMenu on a JMenuBar, then adding that menu bar to the JFrame with setJMenuBar?

Definately not, as there is a gap of some pixels on the left side of the icon. N.B.: using JButton works, so it must be a problem with JMenuItem.

It’s not a problem, it’s by design. You’re not supposed to use JMenuItems outside of menus. See the private method javax.swing.plaf.basic.BasicMenuItemUI#layoutMenuItem for details. The gap is for displaying an optional check mark IIRC.