我有点困惑,因为我无法删除我的JTabbedPane的最后一个选项卡。 我看了这两个问题: first question和second question。但它对我没有帮助。 这是我的代码看起来像:删除jtabbedpane的最后一个选项卡
public void updateTabbedPane()
{
// Remove the MouseListener
tabbedPane.removeMouseListener(tabbedPaneMouseListener);
// Remove all Tabs
while (tabbedPane.getTabCount() > 0)
{
tabbedPane.remove(0);
}
// Sort the ArrayList
Collections.sort(arrayList);
// Add all Element to the JTabbedPane
for (int i = 0; i < arrayList.size(); i++)
{
tabbedPane.addTab(arrayList.get(i).getName(),
new JScrollPane(...);
}
// Add the MouseListiner to the JTabbedPane again
tabbedPane.addMouseListener(tabbedPaneMouseListener);
}
我使用这个方法来添加/删除选项卡,如果添加/删除到列表中的对象。我也对ArrayList进行排序,因为我想让这些选项卡按升序排列。
正如在两个问题的答案中所说的,我在删除Tabs之前删除了MouseListener,但最后一个Tab仍然可见。我也尝试setVisible(),removeAll()。
欢迎任何帮助!
为了更好地帮助越早,张贴[SSCCE(http://sscce.org/)。 –
好吧,我会尝试。 – Steckdoserich
引用的问题是一样的。 – trashgod