Reputation: 12484
I have this code to tell me if a port is open or not(available func). And I call that function in my GUI program like this:
String newavail = "" + available(9002) ;
JTextField tf1 = new JTextField("Is Port 9002(GWT Pet Store) available? \n" + newavail);
But if I close the port outside of the running GUI it doesn't reflect this change right away. I read that you can use a revalidate() command, but how do you use that?
Upvotes: 3
Views: 634
Reputation: 829
Assuming that the port is closed outside the Event Dispatch Thread, you should use SwingUtilities
to set the text of the JTextField
instance to reflect the availability status change.
// we're outside the EDT
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
// modify Swing component here
}
});
Upvotes: 3