我有一个实现多标签聊天的 JFrame 扩展类。每个标签都是与某人或一群人的聊天。我已经实现的工作正常,除非我将 ToolTipText 分配给选项卡的标签。在这种情况下,我不能再单击(并选择)分配了 ToolTipText 的选项卡。其他工作正常。
图形示例:
如您所见,选项卡已正确添加,前两个选项卡(“Gruppo prova”和“Gruppo test”)有一个 ToolTipText,其他两个没有。我可以在最后两个之间切换,但我不能对前两个做同样的事情。我以为标签旁边的图标可能有问题,但我删除了它,仍然不起作用。但是我仍然可以单击所有“X”(关闭)按钮(正常工作)。
这是我用来添加标签的一段代码:
// Some stuff...
JChat chat = new JChat(gui.chatClient, email, name, group);
jTabbedPane.add(email, chat); // I instantiated this before
int index = jTabbedPane.indexOfTab(email);
JPanel pnlTab = new JPanel(new GridBagLayout());
pnlTab.setOpaque(false);
// Core function
JLabel lblTitle;
if (group == 1) {
// If it's a group and not a single chat I assign a name, an icon and a ToolTipText to the tab
lblTitle = new JLabel(name, icon, JLabel.LEFT);
lblTitle.setToolTipText(membersList.toString());
} else {
// otherwise I only assign a name to the tab
lblTitle = new JLabel(name);
}
jTabbedPane.setTabComponentAt(index, pnlTab);
// This applies the 'X' (close) button next to the tab name
CloseButton btnClose = new CloseButton(this, jTabbedPane, tabs, email);
lblTitle.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
pnlTab.add(lblTitle);
pnlTab.add(btnClose);
这是一个 Swing 错误还是我做错了什么?