I’ve faced an interesting thing… All goes fine with null object When I add tabs in constructor as
public class TPane extends JTabbedPane
{
public TPane(ImageIcon iconA,ImageIcon iconB)
{
this.addTab("A",iconA,null);
this.addTab("B",iconB,null);
}
}
But when I try to add tab within another object like
public class AClass
{
public void addNewTab(TPane tp, ImageIcon icon)
{
tp.addTab("C",icon,null);//<-- contains null
}
}
… it doesn’t add tab because of null. OK if I change null to lets say a new JLabel() code works fine :S
Here is both previous object usage…
public class BClass extends JPanel
{
private AClass a=new AClass();
private TPane tp=new TPane();
JButton addTabButton=new JButton("add tab");
ImageIcon icon;
public BClass(Image image)
{
icon=new ImageIcon(image);
...
this.add(tp);
...
addTabButton.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
a.addNewTab(tp,icon);
}
});
}
}
So my question is how to add null object to JTabbedPane dynamically?
Any useful comment is appreciated
I am not sure this is the problem. I have tried it successfully, see the example below and its code(although this is a pathological example):