how to change the color of text of tab on mouse over of JtabbedPane?
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.
精彩评论