• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Button look and feel

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The only thing that kept the leeches off of me was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic