For better readability, I've moved some of the code that generates my GUI in classes. Unfortunately I had to make a mistake somewhere because now I'm getting this error:
Exception in thread "AWT-EventQueue-0"
java.lang.NullPointerException
atjavax.swing.plaf.basic.BasicTabbedPaneUI$ScrollableTabSupport.updateView(BasicTabbedPaneUI.java
:3351
)
It happens in javax/swing/plaf/basic/BasicTabbedPaneUI.java
on this line:
private void updateView() {
ERROR HERE: int tabPlacement = tabPane.getTabPlacement();
int tabCount = tabPane.getTabCount();
There's a method in this class that can set the tabPane
to null, but I'm definitelly not calling it:
public void uninstallUI(JComponent c) {
uninstallKeyboardActions();
uninstallListeners();
uninstallDefaults();
uninstallComponents();
c.setLayout(null);
this.tabPane = null;
}
I create the tabbed GUI using my TabbedWindow class:
public final JTabbedPane container;
public TabbedWindow() {
container = new JTabbedPane();
container.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
//More code but nothing with container
}
I then append it to the main JPane:
public void createTabs(Container pane) {
pane.setLayout(new GridLayout(1, 1));
System.out.println("Creating tabbed window.");
TabbedWindow win = new TabbedWindow();
//Inbetween, I append some JFrames to the win.container
//Adding to main pane:
pane.add(win.container);
System.out.println("Done.");
My questions now are:
I can't be sure about the real reasons, but the uninstallUI
has been invoked because I used container.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
before appending other elements.
Because I frankly doesn't understand how the whole thing works I decided to go the safe way:
public void close() {
container.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
closed = true;
}
And after calling close, nothing can be added to the GUI any more.