问题
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.
回答1:
Two options, neither of which have really good general solutions at the moment IMO:
1. Match the system look and feel
In Swing set UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) to make Swing use the system look and feel.
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.
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. Match your JavaFX UI to a cross-platform Swing look and feel
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.
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.
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.
来源:https://stackoverflow.com/questions/37103316/how-to-sync-javafx-and-swing-look-and-feel