如何删除或更改这些标签周围边框的颜色?
另外,当鼠标悬停在标签上时,是否可以让标签文字改变颜色?
答案 0 :(得分:1)
当鼠标移动时,是否可以让标签文本改变颜色 徘徊在它上面?
如this answer中所述,您可以通过JTabbedPane.setTabComponentAt(int index, Component component)方法设置自定义组件以呈现标签标题。所以你可以这样做:
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);
如何删除或更改这些边框周围边框的颜色 标签?
在这种情况下,由外观决定边框颜色。您应该查看L& F默认属性,看看是否允许更改此颜色。例如,你可以执行以下代码来查看L& F默认属性(当然在设置L& F之后):
for(Object key : UIManager.getLookAndFeelDefaults().keySet()){
System.out.println(key + " = " + UIManager.get(key));
}