JTabbedPane.getTabComponentAt(int) 返回 null [英] JTabbedPane.getTabComponentAt(int) returning null
问题描述
我有以下代码:
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);
事情是:
container.getTabComponentAt(0)
返回null
.另一个奇怪的事情是:
returns null
. The other weird thing is :
container.getSelectedIndex()
返回0
.我认为应该发生的合乎逻辑的事情是引用创建的窗口.为什么我收到 null
?我做错了什么?
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?
推荐答案
getTabComponentAt()
返回您可能添加为选项卡标题的自定义组件.您可能正在寻找 getComponentAt()
方法来返回选项卡的内容.getSelectedIndex()
只返回当前选择了第一个选项卡(如果没有选择选项卡,它将返回 -1)
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)
这篇关于JTabbedPane.getTabComponentAt(int) 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!