2011-07-06 49 views
5

我需要确定JTabbedPane中的哪些选项卡需要更新,方法是确定每个选项卡组件的内容。从我可以确定的情况来看,无法使用默认的JTabbedPane模型遍历每个选项卡。遍历JTabbedPane中的选项卡组件

有没有人有任何想法,我可以做什么在这种情况下?

回答

1
+0

getTabComponentAt用于渲染,而不是遍历标签 – GerritCap

+0

@GerritCap问题是过于模糊,可以肯定的是OP后什么_really_ – kleopatra

+0

@GerritCap - 的OP明确的要求的方式以“遍历每个选项卡”。一种方法是使用上述方法。 'getTabComponent()'方法提供了一个Component。该组件不仅可以用于渲染 - 例如可以对其进行检查或修改。 –

14

,如果你使用类似:

int totalTabs = tabbedPane.getTabCount(); 
for(int i = 0; i < totalTabs; i++) 
{ 
    Component c = tabbedPane.getTabComponentAt(i); 
    //other stuff 
} 

可以给你一个起点,做你想做的。

+0

有问题的选项卡也能够被删除。 JTabbedPane是否按顺序保留索引(例如,如果原始索引索引是:0,1,2,3,4和3被删除,则新索引索引0,1,2,3与0,1,2, 4)。 – Cole

+0

这是一个索引,而不是一个标识符。索引被删除后索引发生变化。 –

+0

我想你要使用'getComponentAt'而不是'getTabbedComponentAt',一个返回tabbedPane的组件,一个返回* tab中的组件*。 – Pureferret

0

使用getComponentAt(int index)从容器

相关问题