Align icon and JCheckbox in JPopupmenu

imageicon, java, jcheckbox, jmenuitem, swing

Solution

Have a look at this, in order to achieve what you wanted, I did this,

JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem("Check Me", null, true);
cbmi.setMargin(new java.awt.Insets(5, 25, 5, 5));
cbmi.setIconTextGap(15);
cbmi.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
helpMenu.add(cbmi);

And here is the OUTPUT of the said thingy :

Problem

I have a Problem with some icons and check-boxes in a `JPopupMenu`. The Check-boxes and Icons are not aligned The Items are created like: ``` JMenuItem deleteAttributeMenuItem = new JMenuItem(locale.getString("TREE_AttrDelete"), iconDelete); JMenuItem primaryKeyAttributeMenuItem = new JCheckBoxMenuItem(locale.getString("TREE_AttrChkBoxPK")); ``` Please take a look at the picture: Any tips?

Original source