做到这将是继承JPanel
和您的自定义JPanel
添加到标签面板,而不是最好的办法:
public class EditorPanel extends JPanel {
private JEditorPane editorPane;
// ...
public EditorPanel() {
// ...
editorPane = new JEditorPane(...);
super.add(editorPane);
// ...
}
// ...
public JEditorPane getEditorPane() {
return editorPane;
}
}
添加一个新的标签:
JTabbedPane tabbedPane = ... ;
tabbedPane.addTab(name, icon, new EditorPanel());
然后当你需要使用选项卡窗格访问它:
Component comp = tabbedPane.getComponentAt(i);
if (comp instanceof EditorPanel) {
JEditorPane editorPane = ((EditorPanel) comp).getEditorPane();
}
这是一个bett呃可以选择维护一个单独的列表并尝试将其与标签窗格的索引一起维护。
将它存储在一个变量..? – Brian
@brian并不是我想要达到的目标。例如,如果我导航到不同的选项卡,则存储JEditorPane对象的变量将存储打开的最新选项卡中的一个,而不是该选项卡仅被导航到的那个变量。不知道这是否有道理。我想要的变量来存储任何打开或导航到任何选项卡的JEditorPane。基本上任何当前正在显示的选项卡。 –
将它存储在列表中? –