Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Not able to repaint button  RSS feed

 
Kapil Sakhuja
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends, I am using Eclipse 3.2.1 with JDK5.0, to develope a Swing App. which is basically a control GUI to run some commands on the machine which were earlier being run on DOS shell. The app has a play/pause button, which works analogous to a CD player button. The current image on the button reflects whether it is play or pause.
The main logic is, when the button is pressed, if the current image is play, i change the image to pause and run some business logic steps. The image shows pause icon as long as the steps are running. After the steps are finished, the button icon is changed back to play.
The GUI is created in a seperate class by extending JFrame and the listener class is seperate. The actionPerformed() method goes like this:

public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("PLAY / PAUSE BUTTON HAS BEEN CLICKED");
JButton buttonClicked = (JButton)e.getSource();
Icon currentIcon = buttonClicked.getIcon();
if(currentIcon == controlGUIMainFrameObject.getPlayImageIcon()){//begin if
System.out.println("PLAY BUTTON HAS BEEN CLICKED");
buttonClicked.setIcon(controlGUIMainFrameObject.getPauseImageIcon());
//buttonClicked.repaint();
//buttonClicked.repaint(100);
/*
*some logic goes here....
*
*/

runSteps(); // this calls another method which creates a new process using ProcessBuilder and runs it.
}// end of if
// resetting the play/pause button icon back to play
controlGUIMainFrameObject.getPlayButton().setIcon(controlGUIMainFrameObject.getPlayImageIcon());
// disbling the stop button
controlGUIMainFrameObject.getStopButton().setEnabled(false);

The steps in the runSteps() method execute as is visible from the console System.out.println() statements. The steps take some time to finish (probably 20 sec). I can see the output:
PLAY / PAUSE BUTTON HAS BEEN CLICKED
PLAY BUTTON HAS BEEN CLICKED
but the image doesnt change as soon as this is done !! I tried using repaint() and repaint(timeInMillis), but that also didnt work.

Can somebody help me rectify this problem ?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!