Harshal Mahajan

Greenhorn
+ Follow
since Sep 16, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Harshal Mahajan

I did some research and was able to solve my problem. Hopefully it'll help those who might run into the same problem. Apparently, Swing component repainting is managed by a RepaintManager class which intercepts all paint requests and calls invokeLater() to process the pending requests on the same dispatch thread. Therefore you have no control over exactly when the repainting occurs. However, the method paintImmediately() can be used to cause a Swing component to get updated immediately.

So in my code, I added the following line immediately after the setText():

jlbl.paintImmediately(jlbl.getVisibleRect());
14 years ago
Hi,

I have a simple JFrame program, I have a JButton and JLabel, JLabel is initialize with some value. on button click I want to execute one process which will take more than 3 seconds, before process starts and ends i want to show process status in JLabel. but it always sets last value assigned to label when process gets executed.

public void actionPerformed(ActionEvent event)
{
String actionCommand = event.getActionCommand();
if(actionCommand.equals("Click Me"))
{
jlbl.setText("Process start");
someMethod();
jlbl.setText("Process end");
}
}
private void someMethod()
{
try
{
Thread.sleep(3000);
}
catch (InterruptedException e)
{
System.out.println(e.getMessage());
}
}



Thanks,


harshal
14 years ago