0

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.

Alec Hewitt
  • 805
  • 1
  • 12
  • 21
  • just guessing without seeing the PageLoader: if that's the long-running task, it's wrong to wrap it all into a invoke - instead start a thread that does the background work and when in that thread, call invokelater to pass the result into the EDT. Which is the appropriate place to update related ui properties, as f.i. the frame/tab title – kleopatra Apr 04 '13 at 22:16

2 Answers2

2
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)

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
1

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.

user949300
  • 15,364
  • 7
  • 35
  • 66
  • This will bloat the code. Is not in PageLoader constructor that will have to set the tab title. It's like calling `setVisible()` on a frame constructor. – Jean Waghetti Apr 04 '13 at 16:40
  • The PageLoader constructor doesn't set the title, but at the end of `PageLoader.run() ` it will need some references so it can get at the title and set it. I'll clarify my answer though - thanks. – user949300 Apr 04 '13 at 17:06
  • If he calls `setTitle()`, it is in some way. – Jean Waghetti Apr 04 '13 at 17:09