这是我之前的问题的延续,但它解决了一个具体的问题,对其他人可能有用,所以我想将其作为一个单独的问题发布。
我成功地创建了一个JTabbedPane,但是有一个蓝色边框突出显示哪个选项卡已被选择,我想删除它。
我成功地创建了一个JTabbedPane,但是有一个蓝色边框突出显示哪个选项卡已被选择,我想删除它。
为了澄清我的意思,这是Eclipse中没有蓝色边框突出显示的JTabbedPane的图片:
我尝试过的内容已被注释掉:public class SeaGlassExercise {
public static void initWindow() {
JFrame frame = new JFrame("Application Name");
CustomTabbedPane content = new CustomTabbedPane();
frame.setContentPane(content);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationByPlatform(true);
// try {
// UIManager.setLookAndFeel(
// UIManager.getSystemLookAndFeelClassName());
// } catch (Exception e) {
// e.printStackTrace();
// }
// SwingUtilities.updateComponentTreeUI(frame);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
initWindow();
}
});
}
}
class CustomTabbedPane extends JPanel {
public CustomTabbedPane() {
super(new GridLayout(1, 1));
// UIManager.put("TabbedPane.contentAreaColor", Color.GREEN);
// UIManager.put("TabbedPane.light", ColorUIResource.GREEN);
// UIManager.put("TabbedPane.highlight", ColorUIResource.GREEN);
// UIManager.put("TabbedPane.shadow", ColorUIResource.GREEN);
// UIManager.put("TabbedPane.darkShadow", ColorUIResource.GREEN);
// UIManager.put("TabbedPane.selected", ColorUIResource.GREEN);
// UIManager.put("TabbedPane.borderHightlightColor", ColorUIResource.GREEN);
// UIManager.put("TabbedPane.borderHightlightColor", ColorUIResource.GREEN);
// UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
JTabbedPane tabbedPane = new JTabbedPane();
JComponent panel1 = makeTextPanel("Panel #1");
tabbedPane.addTab("AAA", panel1);
JComponent panel2 = makeTextPanel("Panel #2");
tabbedPane.addTab("BBB", panel2);
JComponent panel3 = makeTextPanel("Panel #3");
tabbedPane.addTab("CCC", panel3);
JComponent panel4 = makeTextPanel("Panel #4");
tabbedPane.addTab("DDD", panel4);
add(tabbedPane);
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}
protected JComponent makeTextPanel(String text) {
JPanel panel = new JPanel();
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
}
额外信息
我目前在使用OS X Mountain Lion操作系统,以及java版本为"1.7.0_25",Java(TM) SE Runtime Environment (build 1.7.0_25-b15)。我正在使用默认的外观(即我没有在代码中使用 .setUI() 指定任何内容)。
以下是我看过的一些问题:
UIManager.put("TabbedPane.focus", new Color(0, true));
来获得所需的结果,这不会删除边框,但应该使其完全透明。 - VGRUIManager.put("TabbedPane.background", Color.GREEN);
。 - Kent Shikamacom.apple.laf.AquaTabbedPaneUI
忽略了这个属性。 - trashgod