There is a JFrame that created through WindowBuilder in Eclipse. I added a JLabel to it, and I hung an icon on the JLabel itself. This is how JLabel was created:
JLabel label = new JLabel(""); label.setIcon(new ImageIcon("C:\\Users\\User\\Desktop\\main.png")); label.setBounds(100, 123, 101, 75); contentPane.add(label);
Also on the window there is a button. Clicking the button should create another JLabel object:
JButton btnNewButton = new JButton("New button"); btnNewButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JLabel label2 = new JLabel(""); label2.setIcon(new ImageIcon("C:\\Users\\User\\Desktop\\main.png")); label2.setBounds(170, 123, 101, 75); contentPane.add(label2); } }); btnNewButton.setBounds(166, 32, 89, 23); contentPane.add(btnNewButton);
But when I click a button, nothing is created.
Where am I wrong?