Java 外观 (L&F)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3954616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 07:32:27  来源:igfitidea点击:

Java Look and Feel (L&F)

javaswinglook-and-feel

提问by rajesh

I am developing a desktop application with Java Swing for my personal use.I am in need of some beautiful Look and Feel for my application. How can I do it using Java or a 3rd party API?

我正在使用 Java Swing 开发一个桌面应用程序供我个人使用。我的应用程序需要一些漂亮的外观。如何使用 Java 或 3rd 方 API 来实现?

回答by Mikle Garin

You can try L&F which i am developing - WebLaF
It combines three parts required for successful UI development:

你可以试试我正在开发的 L&F - WebLaF
它结合了成功的 UI 开发所需的三个部分:

  • Cross-platform re-stylable L&F for Swing applications
  • Large set of extended Swing components
  • Various utilities and managers
  • 用于 Swing 应用程序的跨平台可重新设计的 L&F
  • 大量扩展的 Swing 组件
  • 各种公用事业和经理

Binaries:https://github.com/mgarin/weblaf/releases
Source:https://github.com/mgarin/weblaf
Licenses:GPLv3and Commercial

二进制文件:https : //github.com/mgarin/weblaf/releases
来源:https : //github.com/mgarin/weblaf
许可证:GPLv3商业

A few examples showing how some of WebLaF components look like: Some of WebLaF components

一些示例展示了一些 WebLaF 组件的外观: 一些 WebLaF 组件

Main reason why i have started with a totally new L&F is that most of existing L&F lack flexibility - you cannot re-style them in most cases (you can only change a few colors and turn on/off some UI elements in best case) and/or there are only inconvenient ways to do that. Its even worse when it comes to custom/3rd party components styling - they doesn't look similar to other components styled by some specific L&F or even totally different - that makes your application look unprofessional and unpleasant.

我开始使用全新的 L&F 的主要原因是大多数现有的 L&F 缺乏灵活性 - 在大多数情况下您无法重新设置它们的样式(在最好的情况下,您只能更改几种颜色并打开/关闭某些 UI 元素)和/或者只有不方便的方法可以做到这一点。当涉及到自定义/第 3 方组件样式时,情况更糟——它们看起来与由某些特定 L&F 样式化的其他组件不相似,甚至完全不同——这使您的应用程序看起来不专业和令人不快。

My goal is to provide a fully customizable L&F with a pack of additional widely-known and useful components (for example: date chooser, tree table, dockable and document panes and lots of other) and additional helpful managers and utilities, which will reduce the amount of code required to quickly integrate WebLaF into your application and help creating awesome UIs using Swing.

我的目标是提供一个完全可定制的 L&F,其中包含一组额外的广为人知和有用的组件(例如:日期选择器、树表、可停靠和文档窗格等)以及额外的有用管理器和实用程序,这将减少将 WebLaF 快速集成到您的应用程序中并帮助使用 Swing 创建出色的 UI 所需的代码量。

回答by diegeelvis_SA

You can also use JTattoo (http://www.jtattoo.net/), it has a couple of cool themes that can be used.

你也可以使用 JTattoo ( http://www.jtattoo.net/),它有几个很酷的主题可以使用。

Just download the jar and import it into your classpath, or add it as a maven dependency:

只需下载 jar 并将其导入您的类路径,或将其添加为 maven 依赖项:

<dependency>
        <groupId>com.jtattoo</groupId>
        <artifactId>JTattoo</artifactId>
        <version>1.6.11</version>
</dependency>

Here is a list of some of the cool themes they have available:

以下是他们提供的一些很酷的主题列表:

  • com.jtattoo.plaf.acryl.AcrylLookAndFeel
  • com.jtattoo.plaf.aero.AeroLookAndFeel
  • com.jtattoo.plaf.aluminium.AluminiumLookAndFeel
  • com.jtattoo.plaf.bernstein.BernsteinLookAndFeel
  • com.jtattoo.plaf.fast.FastLookAndFeel
  • com.jtattoo.plaf.graphite.GraphiteLookAndFeel
  • com.jtattoo.plaf.hifi.HiFiLookAndFeel
  • com.jtattoo.plaf.luna.LunaLookAndFeel
  • com.jtattoo.plaf.mcwin.McWinLookAndFeel
  • com.jtattoo.plaf.mint.MintLookAndFeel
  • com.jtattoo.plaf.ntheitroade.NtheitroadeLookAndFeel
  • com.jtattoo.plaf.smart.SmartLookAndFeel
  • com.jtattoo.plaf.texture.TextureLookAndFeel
  • com.jtattoo.plaf.custom.flx.FLXLookAndFeel
  • com.jtattoo.plaf.acryl.AcrylLookAndFeel
  • com.jtattoo.plaf.aero.AeroLookAndFeel
  • com.jtattoo.plaf.aluminium.AluminiumLookAndFeel
  • com.jtattoo.plaf.bernstein.BernsteinLookAndFeel
  • com.jtattoo.plaf.fast.FastLookAndFeel
  • com.jtattoo.plaf.graphite.GraphiteLookAndFeel
  • com.jtattoo.plaf.hifi.HiFiLookAndFeel
  • com.jtattoo.plaf.luna.LunaLookAndFeel
  • com.jtattoo.plaf.mcwin.McWinLookAndFeel
  • com.jtattoo.plaf.mint.MintLookAndFeel
  • com.jtattoo.plaf.ntheitroade.NtheitroadeLookAndFeel
  • com.jtattoo.plaf.smart.SmartLookAndFeel
  • com.jtattoo.plaf.texture.TextureLookAndFeel
  • com.jtattoo.plaf.custom.flx.FLXLookAndFeel

Regards

问候

回答by TheArchon

Heres the code that creates a Dialog which allows the user of your application to change the Look And Feel based on the user'ssystems. Alternatively, if you can store the wanted Look And Feel's on your application, then they could be "portable", which is the desired result.

下面是创建对话框的代码,它允许应用程序的用户根据用户的系统更改外观。或者,如果您可以将所需的外观和感觉存储在您的应用程序中,那么它们可以是“可移植的”,这就是所需的结果。

   public void changeLookAndFeel() {

        List<String> lookAndFeelsDisplay = new ArrayList<>();
        List<String> lookAndFeelsRealNames = new ArrayList<>();

        for (LookAndFeelInfo each : UIManager.getInstalledLookAndFeels()) {
            lookAndFeelsDisplay.add(each.getName());
            lookAndFeelsRealNames.add(each.getClassName());
        }

        String changeLook = (String) JOptionPane.showInputDialog(this, "Choose Look and Feel Here:", "Select Look and Feel", JOptionPane.QUESTION_MESSAGE, null, lookAndFeelsDisplay.toArray(), null);

        if (changeLook != null) {
            for (int i = 0; i < lookAndFeelsDisplay.size(); i++) {
                if (changeLook.equals(lookAndFeelsDisplay.get(i))) {
                    try {
                        UIManager.setLookAndFeel(lookAndFeelsRealNames.get(i));
                        break;
                    }
                    catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                        err.println(ex);
                        ex.printStackTrace(System.err);
                    }
                }
            }
        }
    }