It's not a secret anymore!*
The moose likes JavaFX and the fly likes Force immediate display of text in a TextField? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Force immediate display of text in a TextField?" Watch "Force immediate display of text in a TextField?" New topic
Author

Force immediate display of text in a TextField?

L Purcell
Greenhorn

Joined: Feb 19, 2012
Posts: 12
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

Joined: Nov 04, 2009
Posts: 140

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


SCJP, SCWCD, SCJD
L Purcell
Greenhorn

Joined: Feb 19, 2012
Posts: 12
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

Joined: May 03, 2008
Posts: 4531
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

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.
 
jQuery in Action, 2nd edition
 
subject: Force immediate display of text in a TextField?