How to insert a jTabbedPane into a jPanel of another class

2

How can I add a JtabbedPane of a class, into a jPanel of another class? Is it possible?

In the 'ConfEmpresa' class I created a container and added the JtabbedPane called 'jTabConfCompany'.

public class ConfEmpresa extends javax.swing.JFrame {
public static Container ct;    

public ConfEmpresa() throws SQLException {
    ct.add(jTabConfEmpresa);
}

Now in the 'Settings' class I want to show this 'jTabConfCompany' through a one-button action:

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         

     jPanelPrincipal.add(ConfEmpresa.ct.getComponent(0));
     jPanelPrincipal.setVisible(true);  
}        

When I click the button to show this JTabbedPane it gives the following error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    
asked by anonymous 23.10.2014 / 12:50

2 answers

2

Where did you instantiate Container ct ?

According to what you said, the problem is here:

jPanelPrincipal.add(ConfEmpresa.ct.getComponent(0));

ct.getComponent(0) is null because it is probably not instantiated.

    
23.10.2014 / 14:26
1

I honestly still have not figured out how to use what you're trying to do.

But try something like this:

public class ConfEmpresa extends javax.swing.JFrame {
public static Container ct = new Container();
public JTabbedPane jtab; 

public ConfEmpresa() throws SQLException {
    jtab=jTabConfEmpresa;
    ct.add(jTabConfEmpresa);
}
public JTabbedPane getjTab(){
     return jtab;
}

then in the other frame :

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     // verifica se ConfEmpresa está instanciado
     jPanelPrincipal.add(ConfEmpresa.getjTab());
     jPanelPrincipal.setVisible(true);  
}

I do not know if you can understand the idea but I think this is the way you should go ...

    
23.10.2014 / 14:42