简体   繁体   English

JButton Windows外观

[英]JButton Windows Look and Feel

I want get this appearance for a JButton: 我想得到一个JButton的外观:

lookandfeel1

I have tried to change the Look and Feel to Windows this way: 我试图通过这种方式将外观更改为Windows:

  UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

but it is shown as: 但显示为:

lookandfeel2

Thanks in advance! 提前致谢!

Taking the comment train to a standalone answer: 将评论列为独立答案:

    // sets the look and feel to be that of the operating system's
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | 
        InstantiationException | 
        IllegalAccessException | 
        UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }

I upvoted kiheru, but it seems like you're not setting it at the right time. 我赞成kiheru,但好像您没有在正确的时间设置它。 You need to run this code before the components are displayed - I usually insert this into the original run() method that starts my application, though it varies if I include a splashscreen. 您需要在显示组件之前运行此代码 -我通常将其插入启动我的应用程序的原始run()方法中,尽管如果包含启动画面,它也会有所不同。

Also, in future ( especially when talking about GUI code, which can get horrendous) people prefer it if you post runnable code examples, so we can see exactly where you might be getting things wrong :) 另外,在将来( 尤其是在谈论GUI代码时,它可能会变得可怕),如果您发布可运行的代码示例,人们会更喜欢它,这样我们可以确切地看到您可能在哪里弄错了:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM