How can I remove OR change colour of the border surrounding these tabs?
ALSO, is it possible to have the tab text change colour when the mouse is hovering over it?
How can I remove OR change colour of the border surrounding these tabs?
ALSO, is it possible to have the tab text change colour when the mouse is hovering over it?
Is it possible to have the tab text change colour when the mouse is hovering over it?
As stated in this answer you can set a custom component for rendering the tab title, through JTabbedPane.setTabComponentAt(int index, Component component) method. So you can do something like this:
final JTabbedPane tabbedPane = new JTabbedPane();
MouseListener mouseListener = new MouseAdapter() {
Color defaultColor;
@Override
public void mouseEntered(MouseEvent e) {
JLabel label = (JLabel)e.getSource();
defaultColor = label.getForeground();
label.setForeground(Color.BLUE);
}
@Override
public void mouseExited(MouseEvent e) {
JLabel label = (JLabel)e.getSource();
label.setForeground(defaultColor);
}
@Override
public void mouseClicked(MouseEvent e) {
JLabel label = (JLabel)e.getSource();
Point point = SwingUtilities.convertPoint(label, e.getPoint(), tabbedPane);
int selectedTab = tabbedPane.getUI().tabForCoordinate(tabbedPane, point.x, point.y);
switch(e.getButton()){
case MouseEvent.BUTTON2: tabbedPane.removeTabAt(selectedTab); break;
default: tabbedPane.setSelectedIndex(selectedTab);
}
}
};
JLabel tab1 = new JLabel("Tab1");
tab1.addMouseListener(mouseListener);
tabbedPane.addTab(null, new JPanel());
tabbedPane.setTabComponentAt(0, tab1);
How can I remove OR change colour of the border surrounding these tabs?
It's up to the Look and Feel decide the border color in this case. You should look into the L&F default properties and see if it's allowed change this color. For instance you could execute the following code to see L&F default properties (of course after setting the L&F):
for(Object key : UIManager.getLookAndFeelDefaults().keySet()){
System.out.println(key + " = " + UIManager.get(key));
}