0

I have added an image to the menu item but in the same menu I used a checkbox item and the result is not very appealing to the eye.. The tick box and the image is not vertically aligned as the other menu item's images. How can I solve this and why this is happenning? JCheckBoxMenuItem's image is that tick box, isn't it?

JMenu menu_project = new JMenu("Project");
menu_project.setMnemonic(KeyEvent.VK_P);
menubar.add(menu_project);

JMenuItem menuitem_setinputparam = new JMenuItem("Set input parameters");
menuitem_setinputparam.setMnemonic(KeyEvent.VK_I);
menuitem_setinputparam.addActionListener(listener);
menu_project.add(menuitem_setinputparam);

JMenuItem menuitem_showoutput = new JCheckBoxMenuItem("Show all output at the end");
menuitem_showoutput.setMnemonic(KeyEvent.VK_O);
menuitem_showoutput.addActionListener(listener);
menu_project.add(menuitem_showoutput);

menu_project.addSeparator();

JMenuItem menuitem_statistics = new JMenuItem("Statistics", new ImageIcon(this.getClass().getResource("assets/menuitem_statistics.png")));
menuitem_statistics.setMnemonic(KeyEvent.VK_S);
menuitem_statistics.addActionListener(listener);
menuitem_statistics.setToolTipText("Overview your flow.");
menu_project.add(menuitem_statistics);

Desired:

What I get:

B. Kaan
  • 95
  • 1
  • 8
  • It's difficult to know what the issue is without any code. – sleepToken Jan 29 '20 at 19:26
  • @sleepToken uploded the code. – B. Kaan Jan 29 '20 at 19:32
  • 1
    "JCheckBoxMenuItem's image is that tick box, isn't it?" No, it is not. You have not specified an image for the checkbox item. If you did, you would see the checkbox, then the image, then the text. – FredK Jan 29 '20 at 19:45
  • @FredK If an image's been specified then you don't see that tick. That's way I thought it was it's image. – B. Kaan Jan 29 '20 at 19:51
  • See[link] (https://stackoverflow.com/questions/30701990/add-image-to-jcheckboxmenuitem). Without setting the position, the icon shows when I run the example. – FredK Jan 29 '20 at 20:01
  • 1
    I think I've found an answer that solves mine roughly.. link: https://stackoverflow.com/a/10472124/5050673 – B. Kaan Jan 29 '20 at 20:07

0 Answers0