I have a JFrame that displays JPanels depending on the MenuItem you click. It works, but now I need to call a method once a JPanel is added to the frame and it is being show
It seems it is solved thanks to invokeLater:
public void methodCalledOnceDisplayed() {
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
chartPanel.repaint();
chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(0).getDataArea();
chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(1).getDataArea();
}
});
}
Now there is no IndexOutOfBoundsException: Index: 0, Size: 0
An explanation of why is this happening would be great