我需要从选择选项卡 Jlabel(代码中的 tabLabel)获取文本,以便在程序中使用它
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);
}
最佳答案
将 mouseClicked(MouseEvent)
事件添加到 tabLabel
中,并将此函数 tabLabel.getText()
写入事件函数中。
关于java - 从 jtabbedpane 中的组件 jlabel 获取标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20138955/