File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Button look and feel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Button look and feel " Watch "Button look and feel " New topic
Author

Button look and feel

Smriti Anchu
Ranch Hand

Joined: Dec 21, 2004
Posts: 40
Hi,

I have a login screen. I have a Login button in that. When the enter key is pressed in the textfield, the login button should look depressed (selected) and the application should start loading. Immediately after starting to load say some 5 seconds later, the focus is in the login window only, the login button should look like a normal button.

Does anybody have any idea about this.

I have an idea of implementing the thread concept here. But i donno threads properly, if anybody can help me in this it would be a great favour to me.

thanks and regards
smriti
Jason Kingsley
Greenhorn

Joined: Feb 21, 2004
Posts: 18
Hi there,

Any long running task you should farm off to a worker thread. If you do a search for SwingWorkerThread on Google you'll find some good information on the whole concept.

But in this particular case, you will need a seperate thread as it sounds suspiciously like you're doing the long task in the button pressed event, which is executing in the swing ui thread. So, as your task runs (in the swing ui thread) the form cannot react to any other events because you've essentially hijacked the thread that processes the messages of the event queue.

So, in the button handler method, do whatever you need to do to spawn some worker thread and call start() on it. This method will return immediately and the button handler will complete and the button will look normal again.

Bewarey of what you do in the other worker thread. It should not try and update controls directly from that thread, you'll need to marshal the calls across and, make sure you design your programs well because of concurrency issues between the threads (such as being able to press the button again and spawning another thread that starts doing the same work that has already been spawned in the previous button press.

You will need to have a play around with threads to get a better understanding of them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Button look and feel