Geo Geo - 5 days ago 10
Java Question

JTabbedPane.getTabComponentAt(int) returning null

I have the following code :

JTabbedPane container;
...
AWindow page = WinUtils.buildWindow();
boolean existing = checkIfExists(page); // in this code, this will always be false
if(!existing)
{
String tabName = page.getLoadedFileLocation().getName();
container.addTab(page.getLoadedFileLocation().getName(), page);
}
Component comp = container.getTabComponentAt(0);
int sel = container.getSelectedIndex();
container.setSelectedComponent(page);


the thing is :

container.getTabComponentAt(0)


returns
null
. The other weird thing is :

container.getSelectedIndex()


returns
0
. The logical thing that I think should happen, is to have a reference to the created window. Why am I receiving
null
? What am I doing wrong?

Answer

getTabComponentAt() returns the custom component you might add as the tab title. You might be looking for the getComponentAt() method to return the contents of a tab. The getSelectedIndex() just returns that the first tab is currently selected (it would return -1 for no tabs selected)

Comments