• 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

precedence

 
Ranch Hand
Posts: 164
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have code that change the button text at run time however this does not seem to happen as required

on line 11 it should set the text on button 2 to blank
everything else work fine but it leaves the button with text on it which means that it could be clicked and try to preform the action relating to that button text, one such text could be add to database so i would end up with two entries in my mysql table which is wrong and would cause a problem later in the application
i have had a similar issue before where i wanted text "working" to be written in a text box but it did not take place until the rest of the code had run on that occasion i found a work around but this time i can not any ideas as to how to make this run in the order the appear in the code i should also say that the text on button 5 gets changed by another part of the application and thereby changing the function of button 5 which works perfectly

 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are blocking the event thread. Everything non-trivial you do in the actionPerformed method should be done on a SwingWorker thread, not on the Event Thread.
For example, if you do this:
then the only thing you will see in the GUI is the final "Action Complete" text, and that will happen only after the actionPerfocmed() method finishes.
 
peter m hayward
Ranch Hand
Posts: 164
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this seems to be an area of java i do no understand how do i go about using different threads and how will that help me
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use different Threads in Swing, because (like most GUI frameworks) it is not thread safe. I suggest you start with the Java™ Tutorials section about threads in Swing. That explains how SwingWorker can use other Threads.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Fred Kleinschmidt wrote:You are blocking the event thread. Everything non-trivial you do in the actionPerformed method should be done on a SwingWorker thread, not on the Event Thread.
For example, if you do this:
then the only thing you will see in the GUI is the final "Action Complete" text, and that will happen only after the actionPerfocmed() method finishes.



That's true -- but it only matters if the doSomething() method takes a significant amount of time to complete. In peter's case that method (judging from its name) updates a database, which on my computer with MySQL takes only a couple of milliseconds. You really need something which takes more than half a second or you'd hardly notice the transition to "Action Complete".
 
Fred Kleinschmidt
Bartender
Posts: 732
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True, but he did say

I have had a similar issue before where i wanted text "working" to be written in a text box but it did not take place until the rest of the code had run on that occasion

which suggests something taking a non-trivial amount of time.
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic