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);
}
Was it helpful?

Solution

Add mouseClicked(MouseEvent) event to your tabLabel and write this function tabLabel.getText() in event function.

See how to add MouseEvent

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top