Add Icon next to KeyEvent in JMenuItem

79 views Asked by At

I have a problem with adding icon to the JMenuItem. I saw constructornew JMenuItem (text, icon) but I already used new JMenuItem (text, mnemonic).

Part of my code:    

file = new JMenu("File");
file.addMenuListener(this);
menuBar.add (file);

open = new JMenuItem("Open", KeyEvent.VK_O);
open.addActionListener(this);
open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
Image img = new ImageIcon(this.getClass().GetResource("C:img/openIcon.ico")).GetImage();
open.setIcon(new ImageIcon(img)); // That part returns Null Pointer Exception
file.add(open);

Any ideas how to solve that?

0

There are 0 answers