public void add() {
final JPanel content = new JPanel();
content.add(new JButton("kash"));
JPanel tab = new JPanel();
tab.setOpaque(false);
JLabel tabLabel = new JLabel("Tab " + (++tabCounter));
JButton tabCloseButton = new JButton(closeXIcon);
tabCloseButton.setPreferredSize(closeButtonSize);
tabCloseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int closeTabNumber = tabbedPane.indexOfComponent(content);
tabbedPane.removeTabAt(closeTabNumber);
}
});
tab.add(tabLabel, BorderLayout.WEST);
tab.add(tabCloseButton, BorderLayout.EAST);
tabbedPane.addTab("aaa", content);
tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1, tab);
}
答案 0 :(得分:-2)
将mouseClicked(MouseEvent)
事件添加到tabLabel
并在事件功能中编写此函数tabLabel.getText()
。