Updating a JPanel with an Image
Hi,
Within a gamePanel (set as the content pane) I have player1 (panel), which holds a JLabel containing an ImageIcon. I want to be able to update the player1 JPanel with a different image once the user clicks a button onscreen. My code is as follows:
private JPanel gamePanel, player1;
private ImageIcon fourSpadesL = new ImageIcon("CardsL/FourSpadesL.jpg")
private ImageIcon anotherCard= new ImageIcon("CardsL/anotherCard.jpg")
....
public game()
{
setLayout(null);
setPreferredSize( new Dimension(800,560) );
player1=new JPanel();
player1.setOpaque(false);
player1Text=new JTextField("Player 1");
player1.add(player1Text);
player1.add(new JLabel(fourSpadesL));
player1.setBounds(0,0,80,80);
gamePanel.add(player1)
add(gamePanel);
gamePanel.setBounds(0,0,800,650);
......
}
and the method that the button calls when clicked
public void drawPlayer1Hand()
{
player1.removeAll();
player1.add(new JLabel(anotherCard));
player1.setBounds(0,0,80,80);
gamePanel.add(player1);
setContentPane(gamePanel);
player1Text.setText("new Hand");
}
once this method is invoked, the TextField in the player1 panel is updated as 'new Hand', but the ImageIcons do not change from the original.
Any help would be much appreciated. Thanks, C.

