Add mouseClicked(MouseEvent)
event to your tabLabel
and write this function tabLabel.getText()
in event function.
get title from component jlabel in a jtabbedpane
-
03-08-2022 - |
Question
i need to get text from select tab Jlabel (tabLabel in the code) for using it in the program
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);
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow