How to change tab color on mouse over JtabbedPane?

I need to change the text color of the JtabbedPane tab to MouseOver.

Is it possible to use a mouse listener or is there any other property?

Thanks Jyoti

+3
source share
2 answers

There is no built-in property or method for this.

One option is to create a custom JLabel (or other component), add a MouseListener that will change the color of the mouse input / output.

Example: Example:

class CustomMouseOverJLabel extends JLabel{
    public CustomMouseOverJLabel(String text) {
        super(text);
        addMouseListener(new MouseAdapter(){
            @Override
            public void mouseEntered(MouseEvent e) {
                setForeground(Color.BLUE);
            }
            @Override
            public void mouseExited(MouseEvent e) {
                setForeground(Color.RED);
            }               
        });
    }       
}

Then, when you make an addTab call (name, element), you also set custom header components, for example:

yourTabbedPane.setTabComponentAt(index, new CustomMouseOverJLabel("title"));
+2
source

, .

0

Source: https://habr.com/ru/post/1775784/


All Articles