Ken*_*ama 5 java swing look-and-feel jtabbedpane osx-mountain-lion
这是我之前的问题的延续,但它解决了一个对其他人有用的特定问题,所以我想我会把它作为一个单独的问题发布.
我已经成功创建了一个JTabbedPane,但是有一个蓝色边框突出显示,显示我要删除的选项卡:

为了澄清我的意思,这里是一张JTabbedPane的图片,没有Eclipse的蓝色边框高亮:

我试过的东西已经被注释掉了:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
我目前正在使用OS X Mountain Lion和java版"1.7.0_25",Java(TM)SE运行时环境(版本1.7.0_25-b15)运行我的程序.我使用默认外观(即我没有在我的代码中使用.setUI()指定任何内容).
以下是我看过的一些问题:
请注意,当前方法可能不适用于其他平台/外观和感觉。如果您当前的项目仅适用于您的 Mac,并且您不打算在将来更改此设置,那么在这种情况下它可能会起作用。但通常 Java 应用程序旨在跨不同平台和外观工作。
话虽如此,您可能想看看这篇关于最流行的外观默认值的有趣文章:Windows、Mac OS X 和 Linux 上常见 Java 外观的所有 UI 默认名称。当您查看表格时,您会发现并非所有 L&F 都支持相同的属性,并且在创建 UI 对象 (fi TabbedPaneUI) 时可能会忽略它们。
如果您喜欢 Mac L&F(我喜欢),那么我建议您尝试自定义Seaglass 外观和感觉,它与 Mac 非常相似。这样您将获得以下好处:
要自定义 Seaglass,您可以列出默认属性,如下所示:
for(Object key : UIManager.getLookAndFeel().getDefaults().keySet()) {
System.out.println(key + " = " + UIManager.get(key));
}
Run Code Online (Sandbox Code Playgroud)
这些太多了,我真的没有足够的时间给你一个可行的例子,所以我希望这个想法足以帮助你。
如果您不希望框架和对话框具有 Seaglass 提供的默认装饰(这对我来说非常难看),那么您需要执行以下操作:
UIManager.setLookAndFeel(new SeaGlassLookAndFeel());
JFrame.setDefaultLookAndFeelDecorated(false);
JDialog.setDefaultLookAndFeelDecorated(false);
Run Code Online (Sandbox Code Playgroud)
这样,框架和对话框将拥有当前窗口管理器(取决于操作系统)提供的窗口装饰。
| 归档时间: |
|
| 查看次数: |
3067 次 |
| 最近记录: |