Erreur java : JTabbedPane dans un JSplitPane
Résolu
duchnoki
Messages postés
166
Statut
Membre
-
duchnoki -
duchnoki -
Bonjour,
J'essaie de mettre un JTabbedPane dans un JSplitPane. Mon splash s'affiche, mais j'obtiens ces erreurs :
Mon code :
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;
}
}
Configuration: Eclipse SDK 3.5.1 Ubuntu 9.10 (Karmic)
2 réponses
-
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); -
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; } }