Re: JTextFields not updating
Are you saying that your program fails even if the user presses the JOptionPane "OK" button making the JOptionPane go away?
Re: JTextFields not updating
Also, your code shows little information on how you're handling your communication with regard to the Swing event thread.
Re: JTextFields not updating
Here is the compilable code in attachments.
Observe the JOptionPane in the server method in two files.
First is b.java -> Here the textfields are updated.
Second is c.java -> Here the textfields are updated when SocketTimeoutException occurs. If there is no timeout defined, then they never get updated. If there is JOptionPane, then it is the same.
I got trouble in attaching files here, so I have put them on my Google Drive https://docs.google.com/folder/d/0Bz...40a0xrRnM/edit
How can I update those fields without the JOptionPane?
Re: JTextFields not updating
I'd rather you post the salient code here. I'm of the philosophy that if you're asking for free advice, the onus is on you to try to make it as easy as possible for us to be able to help you. I prefer an SSCCE, but will review a reasonable amount of non-SSCCE code if it is written so that it is easy to understand. Also, please go into greater detail on your code's expected and observed behavior. Again, what happens if the user handles the dialogs and they go away?
Re: JTextFields not updating
Sorry for posting code like that. It is scrambled as many parts all over my program. So it made me hard to post as short and simple as possible as I can. And I compiled on JDK 7
In b.java(second code in the first post of thread) -> the JOptionPane is written after the ipfield and portfield are updated with setText(). When I run this code these fields are actually updated with the desired data (my external ip and opened port for socket [getLocalPort()] ) and then the message dialog appears. //But as long as the user doesn't click the ok button, the socket.accept() is not called.
In c.java(first code)-> the JOPane is written before the ipfield and portfield are updated. Running this, first the dialog comes and user clicks ok. The next line in the code is to update the ipfield and portfield before the socket.accept() is called but it is not happening - they are not updated. But when the timeout occurs and exception is thrown then these two fields are updated. (If there is no timeout then those two fields are never updated)
I didn't understand why they were not updating.
//I am unable to attach screenshot. When I click on "Manage Attachments" a new empty window opens up.
Re: JTextFields not updating
It sounds like you've likely got a threading issue. Are you using a SwingWorker for your background thread work? If not, look into doing this.
Re: JTextFields not updating
Quote:
Originally Posted by
Fubarable
It sounds like you've likely got a threading issue. Are you using a SwingWorker for your background thread work? If not, look into doing this.
No, I am not using it.I will try it.
Thanks.