Hello. I have a project where I use JTabbedPane. I want to handle an event when a new tab is added to it. I used ContainerListener (). But it turns out that when I add several tabs in the loop, then the listener is called for each one, but physically they have not yet been added, respectively, I cannot get their contents. How to perform processing after the tab is completely added to the panel.
Calling Add Tabs
matchParseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { for (int i = 0; i < 5; i++) { final String url = teamsIds.get(i); SwingUtilities.invokeLater(new Runnable() { public void run() { secondWebBrowser = new JWebBrowser(); System.out.println(secondWebBrowser .navigate("http://www.flashscore.com/match/" + url + "/#h2h;overall")); tabbedPane.addTab("New Tab", secondWebBrowser); } }); Listeners
tabbedPane.addContainerListener(new ContainerListener() { @Override public void componentRemoved(ContainerEvent e) { // TODO Auto-generated method stub } @Override public void componentAdded(ContainerEvent e) { //webBrowser.` System.out.println("added"); if (tabbedPane.getComponentAt(1) instanceof JWebBrowser) { System.out.println(secondWebBrowser.getHTMLContent()); } } }); SecondWebBrowser returns null, because all 5 tabs are added after the loop completes at the same time.