开发者

how to change the color of text of tab on mouse over of JtabbedPane?

开发者 https://www.devze.com 2023-01-25 17:14 出处:网络
I need to change the color of text of tab of JtabbedPane on MouseOver. Is is开发者_如何学运维 possible using the Mouse Listener or is there any different property to do that?

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

Is is开发者_如何学运维 possible using the Mouse Listener or is there any different property to do that?

Thanks Jyoti


There is not a built-in property or method to do this.

One option is to create a custom JLabel (or other component) add a MouseListener that would change the color on mouse entry/exit.

Example, something like this:

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 a call to addTab(title, item), also set custom title components like so:

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


The tabbed pane tutorial has an example of tabs with custom components that might help.

0

精彩评论

暂无评论...
验证码 换一张
取 消