I have been given an assignment in which i need to a use JCheckBoxMenuItem and add an image to it on the right side
I've used the setIcon() method.
Created a custom panel and added image to it and then adding the panel to checkbox.
Tried to add panel like below.
JCheckBoxMenuItem item = new JCheckBoxMenuItem();
item.setText("Option1");
JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JLabel label = new JLabel(new ImageIcon(
"C:\\Users\\abcd\\Desktop\\facebook.jpg"));
panel.add(label);
item.add(panel);
The above seemed like working but only image on the right side was visible and the checkbox and text were missing.
This can be done with a standard check box menu item, simply by adjusting the horizontal text position.