gpt4 book ai didi

Java - JTabbedPane - 添加新面板时出现 ArrayIndexOutOfBoundsException

转载 作者:行者123 更新时间:2023-12-02 08:00:46 26 4
gpt4 key购买 nike

我在使用 JTabbedPane 并向其中添加新选项卡时遇到了一个奇怪的问题。

public void addTab(String title, AbstractTab tab) {
int i = tabPanel.getTabCount();
System.out.println("Tab count:" + i);
tab.validate();
tabPanel.insertTab(title, null, tab, title, i);
tabPanel.validate();
tabPanel.setSelectedIndex(i);
}

运行此代码会导致以下异常:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.JTabbedPane.getTitleAt(Unknown Source)
at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.updateHtmlViews(Unknown Source)
at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.componentAdded(Unknown Source)
at java.awt.Container.processContainerEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.Container.addImpl(Unknown Source)
at javax.swing.JTabbedPane.insertTab(Unknown Source)
at View.Swing.Global.**EditorPanel.addTab(EditorPanel.java:383)**
at View.Swing.Developer.DeveloperContentPanel.showNote(DeveloperContentPanel.java:176)
at View.Swing.Developer.DeveloperTreeViewer.clickedTreeElement(DeveloperTreeViewer.java:62)
at View.Swing.Global.TreeNavigation.mouseClicked(TreeNavigation.java:556)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
...

System.out.println(..); 打印

Tab count 1 

奇怪的是,这个方法工作一次,另一次它抛出这个异常。添加的选项卡是类 AbstractTab 的实例,包含 JTextFieldsMetaphaseEditor、滚动条、JLabels >JTextArea 和一些图片 (ImageIcon)。

有人知道这个问题的解决方案吗?

最佳答案

来自 Bugtracker ,也许您多次使用某个组件?

Clarify in documentation that no 2 tabs in a JTabbedPane can have the same component assigned to them.. causes java.lang.ArrayIndexOutOfBoundsException: 1 > 0

关于Java - JTabbedPane - 添加新面板时出现 ArrayIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8952901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com