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.
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.
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.
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.
subject: Force immediate display of text in a TextField?