Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Button look and feel

 
Smriti Anchu
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic