Bonjour,

Je suis présentement entrain de développer une application comportant plusieurs onglets et sous-onglets.

Je n'arrive pas à diviser ma classe d'interface en sous-classes comportant les onglets. Seulement les titres du JTabbedPane s'affichent.

J'aimerais avoir une classe pour chacun de mes onglets, et non tout avoir dans la même classe.

Voici donc un peu de code que j'ai simplifié

Interface.java:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
public class Interface extends JPanel 
{
    private JTabbedPane tabbedPane = new JTabbedPane();
    public Interface() 
    {
        super(new BorderLayout());
        super.setBackground(Color.WHITE);
        JPanel onglet1 = new ong1();
        tabbedPane.addTab("Générer livrable", null, onglet1, null); 
        add(tabbedPane);
    }
 
    public static void createAndShowGUI() 
    {    
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocation((screenSize.width / 2 - 300), (screenSize.height / 2 - 240));
        frame.setResizable(false);
        Interface i = new Interface();
        i.setOpaque(true); 
        i.setBorder(BorderFactory.createEmptyBorder());
        frame.setContentPane(i);
        frame.pack();
        frame.setSize(600, 480);
        frame.setVisible(true);
    }
 
    public static void main(String[] args) 
    {
        javax.swing.SwingUtilities.invokeLater(new Runnable() 
        {
            public void run() 
            {
                createAndShowGUI();
            }
        });
    }
}
ong1.java

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 
public class ong1 extends JPanel
{
    private JLabel onglet1_lblBD=new JLabel("Mandat: ");
    private JLabel onglet1_lblLivraison=new JLabel("Livraison: ");
    private JLabel onglet1_lblVersion=new JLabel("Version: ");
    private JComboBox onglet1_cboBD = new JComboBox();
    private JComboBox onglet1_cboLivraison = new JComboBox();
    private JComboBox onglet1_cboVersion = new JComboBox();  
    private JLabel onglet1_lblFichier = new JLabel("Fichier livrable: ");
    private JTextField onglet1_txtFichier = new JTextField(80);
    private JButton onglet1_btnParcourir = new JButton("...");
    private JButton onglet1_btnOK = new JButton("OK");
    private Border paneEdge = BorderFactory.createEmptyBorder(380,500,10,10);
 
    //variables d'alignement de l'interface
    int leftAlign = 210;
    int rightAlign = 303;
    int topAlign;
 
    Dimension posBtnOK = new Dimension(259,340);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    public JPanel panel1 = new JPanel();
 
    public ong1() 
    {
        panel1.setBorder(paneEdge);
        //panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
        panel1.setLayout(null);
        panel1.setBackground(Color.WHITE);
        Object[] tabLivraison= {"",1,2,3,4,5,6};
        Object[] tabVersion = {"",1,2,3,4,5,6,7,8,9};     
        onglet1_cboLivraison = new JComboBox(tabLivraison);
        onglet1_cboVersion = new JComboBox(tabVersion);
        topAlign = 70;
        onglet1_lblBD.setBounds(new Rectangle(leftAlign,topAlign-20,100,20));
        onglet1_cboBD.setBounds(new Rectangle(rightAlign,topAlign-20,100,20));
        onglet1_lblLivraison.setBounds(new Rectangle(leftAlign,topAlign+10,100,20));
        onglet1_cboLivraison.setBounds(new Rectangle(rightAlign,topAlign+10,40,20));      
        onglet1_lblVersion.setBounds(new Rectangle(leftAlign,topAlign+40,100,20));
        onglet1_cboVersion.setBounds(new Rectangle(rightAlign,topAlign+40,40,20));       
        onglet1_lblFichier.setBounds(new Rectangle(leftAlign,topAlign+200,100,20));
        onglet1_txtFichier.setBounds(new Rectangle(rightAlign,topAlign+200,100,20));
        onglet1_btnParcourir.setBounds(new Rectangle(402,topAlign+200,20,20));
        onglet1_btnOK.setBounds(new Rectangle(posBtnOK.width,posBtnOK.height,80,20));
 
        panel1.add(onglet1_lblBD);
        panel1.add(onglet1_cboBD);
        panel1.add(onglet1_lblLivraison);
        panel1.add(onglet1_cboLivraison);
        panel1.add(onglet1_lblVersion);
        panel1.add(onglet1_cboVersion);
        panel1.add(onglet1_lblFichier);
        panel1.add(onglet1_txtFichier);
        panel1.add(onglet1_btnParcourir);
        panel1.add(onglet1_btnOK);
        onglet1_txtFichier.setFont(new Font(null, Font.BOLD, 12));
        onglet1_btnParcourir.addActionListener(gererBoutons);       
        onglet1_btnOK.addActionListener(gererBoutons);         
        onglet1_btnOK.setEnabled(false);
        onglet1_txtFichier.setEditable(false);
    }