我有一个JPanel,其中我有一个JLabel,其中包含一个Image,如下所示:
JLabel imageLabel = new JLabel(new ImageIcon(image));
之后,我设置 的bounds,imageLabel如下所示:
//I want the Image to be in the middle of the screen!
imageLabel.setBounds((int) (screenSize.getWidth() / 2 - image.getWidth(null) / 2),
(int) (screenSize.getHeight() / 2 - image.getHeight(null) / 2),
image.getWidth(null), image.getHeight(null));
然后我imageLabel将JPanel.
add(imageLabel);
现在我想Image通过使用KeyEvent(KeyEvent作品)来改变 , 。我认为,它改变了Image(通过使用image = any other Image),但它不会在屏幕上改变。
我怎样才能做到这一点?我试图将revalidate()和添加repaint();到 JPanel。