如何同步JavaFx和Swing外观 [英] How to sync JavaFx and Swing Look and Feel

查看:80
本文介绍了如何同步JavaFx和Swing外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有JavaFx应用程序,其中嵌入了swing组件. JavaFx和Swing组件的外观不同.因此,我正在寻找能够解决此问题并提供通用外观的解决方案,以使应用程序看起来更加专业并为用户所接受.

I have JavaFx application in which I embedded the swing components. Look and Feel of JavaFx and Swing components differs. So I am in search of solution which can address this issue and provide common look and feel so that application looks more professional and accepted by user.

任何帮助都非常有用.

Any help is greatly appriciated.

推荐答案

两个选项,在IMO时,这两个选项都没有非常好的通用解决方案:

Two options, neither of which have really good general solutions at the moment IMO:

1.匹配系统外观

在Swing中设置 UIManager. setLookAndFeel(UIManager.getSystemLookAndFeelClassName())使Swing使用系统外观.

In Swing set UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) to make Swing use the system look and feel.

JavaFX默认情况下不匹配系统外观,并且不了解Swing UIManager. JavaFX具有自己的内置跨平台外观和感觉(使用自定义外观和样式覆盖默认平台外观有些人甚至为JavaFX创建了一些系统外观,例如 AquaFX ,但是没有通用的系统外观并获得对可运行JavaFX的所有系统的支持.

JavaFX does not, by default, match the system look and feel and has no knowledge of the Swing UIManager. JavaFX has it's own in-built, cross-platform look and feel (Modena in Java 8 and Caspian in Java 7). You can override the default platform look and feel with a custom look and feel and some people have even created some system look and feels for JavaFX, for example AquaFX, but there is no general system look and feel support for all systems on which JavaFX can run.

您可以检查要支持的平台,以查看是否可以找到将JavaFX与这些平台的系统外观匹配的第三方定义.我的猜测是,如果您想在各种平台上实现高质量的系统外观匹配,那么按照这种方法,您将无法获得令人满意的解决方案.

You can check for the platforms you wish to support to see if you can find third party definitions that match JavaFX to the system look and feel of those platforms. My guess is, that if you want high quality matching of system look and feels across a variety of platforms, that you will not get a satisfactory solution going this route.

2.使您的JavaFX UI与跨平台的Swing外观匹配

这将需要为您的应用程序选择跨平台的Swing外观,然后为JavaFX应用程序定义一个用户代理样式表,该样式表将JavaFX小部件外观与Swing小部件外观匹配.基于JavaFX CSS的样式非常灵活.通过一些工作,您可以模拟许多窗口工具箱的外观(如此按钮样式示例).因此,您当然可以构建一些东西来匹配一些常见的Swing外观.

This would require choosing a cross-platform Swing look and feel for your application, then defining a user-agent stylesheet for your JavaFX application which matches the JavaFX widget look to the Swing widget look. JavaFX CSS based styling is very flexible. With some work, you can emulate many windowing toolkit looks (as demonstrated by this button styling sample). So, you could certainly build something to match some common Swing look.

但是,我从未见过有人尝试这样做,对于大量的小部件而言,所需的工作并不平凡,您可能最终会使您的应用程序看起来总体上有点差,以匹配您的Swing接口,然后如果您改为花费精力使JavaFX部分和Swing部分看起来更好,或者只使用默认JavaFX查找JavaFX部分,而使用Swing查找Swing部分.

However, I have never seen anybody attempt to do this, the work required would be non-trivial for a large number of widgets and you might end up making your application look a bit worse on the whole to match your Swing interface then if you instead spent that effort making the JavaFX portions and Swing portions look better or just used the default JavaFX look for just the JavaFX parts and the Swing look for the Swing parts.

因此,实际上,您剩下的是第三种选择,这是最现实的IMO:接受您的应用程序的Swing部分和应用程序的JavaFX部分看起来会有所不同.如果这是您的应用程序无法接受的折衷方案,请转换您的应用程序以使用单个工具箱(Swing或JavaFX)来呈现UI控件.

So, really, you are just left with a third option, which is the most realistic IMO: accept that the Swing parts of your application and the JavaFX parts of your application will look a bit different from each other. If that is an unacceptable compromise for your application, convert your application to use a single toolkit (either Swing or JavaFX) to render UI controls.

这篇关于如何同步JavaFx和Swing外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆