I tried to add key and mouse listener to JFrame, it didn't work, also i find out that JFrame can't get focus. I have a function which loads the buffered image where i want to add the mouse and key listener in entire image dimension.
public void imageloader(BufferedImage image) throws InterruptedException {
// frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension dimension = new Dimension(image.getWidth(), image.getHeight());
setSize(200, 100);
setVisible(true);
label.removeAll(); //label is Jlabel
label.setIcon(new ImageIcon(image));
frame.setSize(dimension);
label.revalidate();
JScrollPane pane = new JScrollPane(label,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
frame.getContentPane().add(pane);
frame.setSize(dimension);
// frame.setVisible(true);
}
How can be mouse and key listener be added to this image frame without moving parts from this function?