• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Force immediate display of text in a TextField?

 
L Purcell
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using (learning to use!) Java and Scene Builder. In the Initialize method in the Controller, I start a connection to a device which takes awhile (but actually works!). Thus I would like to display "Waiting for attachment" in a TextField so the user will know this. However, the TextField doesn't appear to show the text until the Initialize method is completed! (In VC++ I used doEvents in such a case.) Is there a way to force immediate display of text? Thanks.
 
Dennis Grimbergen
Ranch Hand
Posts: 159
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see you are talking about JavaFX :-)
You probably need to start a connection to your device in a separate thread. At the moment you use the JavaFX application thread for it, and as long as you don't have a connection to your device the rest of the application blocks. That's why you see your textfield from the moment the connection has been established.

More info here: JavaFX threads
 
L Purcell
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis, thanks. I had thought about the blocking, so I had moved my setText command AHEAD of the call for the device attachment. If I could then insert a command of some sort to force the text to display, again ahead of the attachment call, all would be well. (Re threads, the actual attachment calls, etc, from the device jar actually use threads, they say.) FYI the device is a Phidget - rather neat USB I/O.
 
Darryl Burke
Bartender
Posts: 5128
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Grimbergen wrote:I see you are talking about JavaFX :-)

Thanks for noticing that.

L Purcell, I've moved the thread to the area where our resident FX experts hang out.
 
Darryl Burke
Bartender
Posts: 5128
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regardless of the order of your lines of code, any operation that may be time consuming or block shouldn't be executed on the Application thread ... unless of course you actually want to force the UI to be unresponsive. This isn't unique to JavaFX or even to Java. Pretty much every UI toolkit in any language, on any platform, is single threaded and can be made unresponsive by running things on that thread that shouldn't be.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic