How to insert a jTabbedPane into a jPanel of another class

Asked

Viewed 375 times

2

How can I add a Jtabbedpane of one class to a jPanel of another class? Possible?

In the 'Confempresa' class I created a container and added Jtabbedpane which is called 'jTabConfEmpresa'.

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

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

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

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

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

When I press the button to show this Jtabbedpane gives the following error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  • 3

    Could you elaborate more on your question? In the same Jframe or when you go from one jframe to another? and post some code also helps...

  • I have a jTabbedPane created in a 'Confempresa' class frame. Now I would like to click a button already created in the frame of the class 'Configurations' to show me the jTabbedPane of the class 'Confempresa', in a jPanel of the class 'Configuracoes'. I was explicit? jPanelPrincipal.add(Confempresa.jTabConfEmpresa);

  • 2

    Hugo, please prefer [Edit] the question to add details and format code properly. Check the [Ask] guide to reverse these negative votes.

  • I’ve already edited the question, see if it’s more explicit what I want. I’m sorry but I’m new to these errands.

2 answers

2


Where did you urge Container ct?

According to what you said, the problem is here:

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

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

  • But does confEmpresa.ct not already contain the Jtabbedpane I want? ? when instating it I don’t lose the Jtabbedpane that’s inside? I already got :) Thank you all for your help !!!

  • Share the hiccup.

1

I honestly don’t quite understand what use you’re trying to make.

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 the next frame:

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

I don’t know if I get the idea but I think this is the way you should go...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.