JTabbedPane Tab组件的MouseEvents没有渗透 [英] MouseEvents for a JTabbedPane Tab component are not bleeding through
问题描述
我有一个带有自定义标签组件的 JTabbedPane
。该组件包含 JLabel
(显示标签标题)和 JButton
(关闭按钮)。当我更改 JLabel
中的文本时, JLabel
停止接收鼠标事件,我无法再选择该选项卡直接点击标签,如果我点击标签,然后我可以选择标签。有什么想法?
I have a JTabbedPane
with a custom tab component. That component contains a JLabel
(To display the tab title) and a JButton
(A close button). When I change the text in the JLabel
the JLabel
stops receiving mouse events and I can no longer select that tab when I click directly on the label instead if I click around the label then I can select the tab. Any ideas?
代码片段:
class ShellPanelTabComponent extends JPanel implements ActionListener{
private ShellPanel panel;
private JLabel label;
public ShellPanelTabComponent(final ShellPanel panel){
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
this.panel = panel;
setOpaque(false);
label = new JLabel(panel.getTitle());
label.setFocusable(false);
add(label);
label.setBorder(BorderFactory.createEmptyBorder(2,0,0,5));
//now the button
CloseButton closeButton = new CloseButton(panel);
add(closeButton);
closeButton.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
panel.getShell().removeShellPanel(panel);
}
/**
* @return the label
*/
public JLabel getLabel() {
return label;
}
}
推荐答案
问题与我在进行更多挖掘后发布的问题有关:使用setToolTipText的解决方法鼠标事件?
The problem is related to the one that I posted here after I did more digging: Workaround for setToolTipText consuming mouse events?
这篇关于JTabbedPane Tab组件的MouseEvents没有渗透的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!