Erreur java : JTabbedPane dans un JSplitPane

Résolu/Fermé
duchnoki Messages postés 158 Date d'inscription dimanche 12 octobre 2008 Statut Membre Dernière intervention 30 novembre 2010 - 3 mars 2010 à 16:53
 duchnoki - 5 mars 2010 à 09:24
Bonjour,
J'essaie de mettre un JTabbedPane dans un JSplitPane. Mon splash s'affiche, mais j'obtiens ces erreurs :
Exception in thread "Thread-2" java.lang.IllegalArgumentException: adding a window to a container
	at java.awt.Container.checkNotAWindow(Container.java:431)
	at java.awt.Container.addImpl(Container.java:1039)
	at javax.swing.JTabbedPane.insertTab(JTabbedPane.java:703)
	at javax.swing.JTabbedPane.addTab(JTabbedPane.java:777)
	at wizzer.ui.WZMainWindowContent.<init>(WZMainWindowContent.java:12)
	at wizzer.ui.WZMainWindow.<init>(WZMainWindow.java:10)
	at wizzer.WZMain.init(WZMain.java:16)
	at wizzer.ui.WZSplashScreen$Progression.run(WZSplashScreen.java:82)
	at java.lang.Thread.run(Thread.java:619)

Mon code :
package wizzer.ui;

import javax.swing.*;

public class WZMainWindowContent {
	public JTabbedPane windowContent = new JTabbedPane();
	
	public WZMainWindowContent() {
		JFrame page1 = new JFrame();
		JLabel test = new JLabel("test");
		page1.add(test);
		windowContent.addTab("[Sans nom]", page1);
	}
	
	public void newFrame() {
		//JFrame pages = new JFrame();
		//JLabel
		//windowContent.addTab("[Sans nom]", pages);
	}
	
	public JTabbedPane getWindowContent() {
		return windowContent;
	}
}
A voir également:

2 réponses

duchnoki Messages postés 158 Date d'inscription dimanche 12 octobre 2008 Statut Membre Dernière intervention 30 novembre 2010 4
3 mars 2010 à 17:00
P.S : Il faut savoir que mon JSplitPane est dans une autre classe :
WZMainSideBar sideBar = new WZMainSideBar();
WZMainWindowContent windowContent = new WZMainWindowContent();
		JSplitPane content = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sideBar.getSideBar(), windowContent.getWindowContent());
		content.setOneTouchExpandable(true);
        content.setDividerLocation(200);
0
C'est bon : j'ai trouvé : Il faut créer un (en public) JPanel et mettre le JTabbedPane dedans (en public aussi) :
package wizzer.ui;

import java.awt.BorderLayout;

import javax.swing.*;

public class WZMainWindowContent {
	public JPanel windowContent = new JPanel();
	public JTabbedPane tabs = new JTabbedPane();
	
	public WZMainWindowContent() {
		windowContent.setLayout(new BorderLayout());
		windowContent.add(tabs);
	}
	
	public void newFrame() {
		tabs.addTab("[Sans titre]", new JPanel());
	}
	
	public JPanel getWindowContent() {
		return windowContent;
	}
}
0