Reputation: 824
I am using invokeLater() to load html pages within a JEditPane which is inside a JPanel which is inside a JTabbedPane.
All of my methods work fine for loading the html. The thing I am having trouble with is updating the tab title.
The methods setTitle() and setTabTitle() work however they are being executed before the PageLoader has completed. Therefore the tab title is always displaying the title of the previous html page.
Is there a way I can stop the methods setTitle() and setTabTitle() from executing until after the thread within the invoke later has completed:
here is the part of my code I am looking at:
private void showPage(){
// Load cursors
Cursor cursor = viewer.getCursor();
Cursor waitCursor = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
viewer.setCursor( waitCursor );
SwingUtilities.invokeLater( new PageLoader( viewer, url, cursor) );
//Update tab title
setTitle();
tabPanel.setTabTitle(this);
//Update address bar
addressTextField.setText(url.toString());
}
thanks for any help you can give.
Upvotes: 0
Views: 108
Reputation: 109813
Determining when a process within invokeLater has completed
is possible to test by if (SwingUtilities.isEventDispatchThread()) {
from util.Timer
but this idea isn't good, for why reason to hunting for EDT ended,
EDT not ended in the moments when all events are repainted in the Swing GUI, there are internal proccesses from notifiers implemented in APIs
basically you simulating Workers Thread, use SwingWorker or Runnable#Thread (all events to the visibble Gui must be wrapped into invokeLater)
Upvotes: 2
Reputation: 15729
Put the setTitle()
etc. at the end of the PageLoader.run()
code. You may need to pass this
or some additional variables to it's constructor so that you have access to the title.
Upvotes: 1