【发布时间】:2014-02-17 01:33:56
【问题描述】:
这是我previous question 的延续,但它解决了一个对其他人可能有用的特定问题,所以我想我会把它作为一个单独的问题发布。
我已经成功创建了一个 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 运行时环境(内部版本 1.7.0_25-b15)运行我的程序。我使用的是默认外观(即我没有在代码中使用 .setUI() 指定任何内容)。
以下是我看过的一些问题:
【问题讨论】:
-
与其中一个链接问题中的解决方案类似,您可以通过
UIManager.put("TabbedPane.focus", new Color(0, true));获得所需的结果,这不会删除边框但应该使其完全透明。 -
是的,它应该像所有其他 UIManager.put() 调用一样工作,但事实并非如此。唯一似乎有任何效果的是
UIManager.put("TabbedPane.background", Color.GREEN); -
com.apple.laf.AquaTabbedPaneUI忽略此属性。
标签: java swing osx-mountain-lion look-and-feel jtabbedpane