6

私は次のコードを持っています:

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。他の奇妙なことは:

container.getSelectedIndex()

を返します0。私が起こるべきだと思う論理的なことは、作成されたウィンドウへの参照を持つことです。なぜ私は受け取っているのnullですか?私は何が間違っているのですか?

4

2 に答える 2

21

getTabComponentAt()タブのタイトルとして追加できるカスタム コンポーネントを返します。getComponentAt()タブのコンテンツを返すメソッドを探しているかもしれません。最初のgetSelectedIndex()タブが現在選択されていることを返すだけです(タブが選択されていない場合は-1を返します)

于 2009-06-12T20:05:55.157 に答える