Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trying to repaint() a JLabel

 
tom davies
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a small dice betting game with a GUI.
The users chooses which variation of the game they want to play and how much to bet, then press throw.
I have a JPanel which contains a JLabel, i want this JLabel to refresh with the users current balance when the throw button is pressed.
I have checked and it appears that the balance is being updated bu the JLabel is not being repainted.

Here is my actionListener


The JPanel that holds my balance JLabel.


When the button "roll" is pressed the method below is executed. As you can see i try to repaint the JLabel balance
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
unlike Excel, JLabel's don't have automatic recalculation - you need to set it manually

instead of
balance.repaint();
have
balance.setText("Balance = £" + playerBalance); //repaint() not needed - setText() handles that
 
tom davies
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! works great now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic