gagaliya
asked on
java swing popup.show() doesnt work, help
Hi i am very new to swing. and for the life of me, i cannot get this popup window to show up properly after the mouseclick() is called, i can confirm mouseclick event is definitely clicked by the system.out that got printed. Here's what happened:
1) after mouse click, the popup window will appear but only half loaded, basically a white window with all the text in the middle missing
2) the popup only finish loading and show properly AFTER the entire mouseClicked() function finishes.
question: how do i get the popup window to show up and paint properly as soon as popup.show() is called. I am using it as "loading please wait" window, but right now it just shows a white blank window until everything finishes processing. I want it to draw/paint properly as soon as popup.show() is called.
thanks
1) after mouse click, the popup window will appear but only half loaded, basically a white window with all the text in the middle missing
2) the popup only finish loading and show properly AFTER the entire mouseClicked() function finishes.
question: how do i get the popup window to show up and paint properly as soon as popup.show() is called. I am using it as "loading please wait" window, but right now it just shows a white blank window until everything finishes processing. I want it to draw/paint properly as soon as popup.show() is called.
thanks
public class someListener extends MouseAdapter
{
private Popup popup;
private JLabel sortingProgress;
public someListener ()
{
sortingProgress = new JLabel("Sorting...");
popup = PopupFactory.getSharedInstance().getPopup(null, sortingProgress, 200, 200);
}
public void mouseClicked(MouseEvent e)
{
System.out.println("mouse clicked");
popup.show();
try{Thread.sleep(1000000);}catch(Exception ee){} //or do some processing
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here's some links about the Event Thread.
http://www.swingwiki.org/best:use_worker_thread_for_long_operations
http://en.wikipedia.org/wiki/Event_dispatching_thread
http://www.swingwiki.org/best:use_worker_thread_for_long_operations
http://en.wikipedia.org/wiki/Event_dispatching_thread
To get it to show immediately, you would have to write you own JFrame or JDialog designed to paint without the Event Thread or just dont "block" the Event Thread.
For long processing have a look at using the SwingWorker class
http://java.sun.com/docs/books/tutorial/uiswing/concurrency/simple.html
http://java.sun.com/docs/books/tutorial/uiswing/concurrency/simple.html
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
example splash screen here
http://helpdesk.objects.com.au/java/how-can-i-create-splash-window-in-swing
http://helpdesk.objects.com.au/java/how-can-i-create-splash-window-in-swing
ASKER
Hi guys, i tried following code it worked perfectly on first click, but on 2nd click and onwards nothing happens. From my understanding reading the links, basically the mouseClicked event is running, so the draw has to wait as it's single threaded. But i thought by changing this to mousePressed and mouseReleased, it would solve the problem as aftrer mousePressed, the thread finishes processing, so the poup should be drawn, then mouseReleased kicks in.
It works fine the first click, but then nothing happens on all subsequent clicks, why?
public void mousePressed(MouseEvent e)
{ popup.show(); }
public void mouseReleased(MouseEvent e)
{ try{Thread.sleep(1000000); }catch(Exc eption ee){} //or do some processing
popup.hide();
}
It works fine the first click, but then nothing happens on all subsequent clicks, why?
public void mousePressed(MouseEvent e)
{ popup.show(); }
public void mouseReleased(MouseEvent e)
{ try{Thread.sleep(1000000);
popup.hide();
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you all!
// add actions to your popup here
sortingProgress.setCompone