Look and feel mechanism?

Hendrik Ebbers hendrik.ebbers at me.com
Mon Dec 9 01:45:06 PST 2013


I played a little with a L&F API for JavaFX before JavaOne. Here are my results:


- The UI of all controls is defined by CSS. For a new L&F an additional or new CSS is needed

- The Behavior of controls is defined by the Behavior class that is defined by the skin. The skin can be set in CSS and because of that the complete behavior could be set by CSS. The biggest problem in this case is that the Behavior API is still a private API.

- If the Behavior API will become public API and some of it's internals will be refactored (additional constructors for example) all controls depended stuff could be defined in a Look and Feel. The entry point here will be a CSS.

- You can define a static helper class that sets the CSS for a complete application. This is done in AquaFX for example. (doc:

Let's think about additional controls. ControlsFX adds a lot of great controls that hopefully will be used in applications. If you want to define a new Look and Feel these controls need to be skinned, too.

Thanks to JavaFX and CSS we can simply define a hierarchy of CSS classes. By doing so plugins for Look and Feels could be defined. The base Look and Feels defines a CSS file that styles all the default controls and defines some basic colors. Based on this a Plugin adds a CSS file that skins only some additional controls.

For a JavOne talk I created a very simply framework that does exactly this stuff. It defines some basic classes and interfaces for Look and Feels and Plugins. When we take ControlsFX and AquaFX as a example the workflow will be like this:

AquaFX has a implementation of the LookAndFeel class. By using the default Look And Feel API a L&F can be set (LookAndFeel.getInstance().set(aquaLaF);). By doing so we can set the AquaFX L&F. When a L&F is set the classpath will be searched for plugins for the AquaFX L&F. Here the SPI API that is part of the JDK (
) can be used. Each plugin that is found will be loaded. Because ControlsFX supports the AquaFX L&F it provides a plugin for this L&F. To do so ControlsFX don't depend on AquaFX. It only depends on the L&F API and implements the plugin interface of the API. here it can offer a CSS file that styles all ControlsFX controls in Aqua-Style. If the plugin needs dependencies to AquaFX (because it adds some special skin classes that needs basic features form AquaFX) a additonal module ControlsFX-AquaFX could be created. This module depends on AquaFX, ControlsFX and the L&F Framework.

Next to the skinning of controls additional features are needed. One example that was already mentioned is the order of cancel and ok buttons. Actually there is no support in JavaFX. If basic dialogs would support this features a definition of the order etc. is needed. This can be done by using a plugin for the L&F API, too. A plugin don't only set a CSS. A plugin could do mainly everything. Example: If there would be a DialogOrderFX class that defines the order of Buttons a plugin can call DialogOrderFX.getInstance().set(windowsMetroOrder) for example.

You can find the slides of the JavaOne talk here:

On slide 41 the "StyleManager" part starts. 


> Am 09.12.2013 um 09:10 schrieb Felix Bembrick <felix.bembrick at gmail.com>:
>> On 9 December 2013 16:10, Scott Palmer <swpalmer at gmail.com> wrote:
>>> On Dec 8, 2013, at 9:18 PM, Felix Bembrick <felix.bembrick at gmail.com>
>> wrote:
>> <snip>
>>> Firstly, it will *never* be possible to completely emulate the native
>> look
>>> and feel.
>> Sure it is. Though it may never be practical, for many of the reasons you
>> have given.
>>> My reasoning is: why bother?
>> Because it matters. As computer literate developers, we often don't
>> realize what trips other people up.  I get so frustrated with apps these
>> days because they have become hard to use simply because the developers
>> tried to define their own look and feel.  For example, Chrome and
>> Firefox... Or Microsoft Office...
>> Where did the title bar go in chrome?
>> Where have all the menus gone in Chrome, Firefox andOffice?  I can find
>> them, but when I have to play tech support over the phone to my parents
>> these changes are massive problems. I ask my dad to move he window by
>> dragging the title bar (please don't ask why he doesn't know to do this
>> himself after decades of computer use) and he says "there is no title
>> bar"... I the remember that yes, chrome did that... They got rid of a
>> standard concept in the OS' windowing system and screed the end users.
>> These apps became harder to use because of this "innovation" in the UI.
>> Contrast this with applications on OS X where getting the UI right has
>> always been an important priority for developers.  Because adhering to the
>> system look and feel has always been strongly encouraged the system is much
>> easier to use.
>>> These days, many apps do not look 100% native and may have their own
>>> controls or look and feel in general.
>> Yes, but to what end? They are now more difficult to use.
>>> Why not channel all that massive
>>> effort in constructing an emulated native look and feel into simply
>> making
>>> JavaFX better overall?
>> But I agree here.  The general look isn't the main issue.. E.g. little
>> variations in color and minor tweaks to a few pixels here and there don't
>> really matter.  What does matter is when you change the order of buttons,
>> like Okay & Cancel which have standard places that are different between
>> Mac and Windows, or you move the About menu item from the Application menu
>> on an OS X app to the help menu! because that is where you find it on
>> Windows.  Those things matter.
>> Scott
>>> Felix
>>> On 9 December 2013 12:35, Pedro Duque Vieira <
>> pedro.duquevieira at gmail.com>wrote:
>>>> Thanks!
>>>> @Jasper: Yes, that's very interesting! Forgot that was possible to do in
>>>> CSS.
>>>>> On Mon, Dec 9, 2013 at 12:15 AM, Stephen Winnall <steve at winnall.ch>
>> wrote:
>>>>> It may be possible to change the LOOK with CSS, but not the FEEL, which
>>>> is
>>>>> where Java apps have traditionally failed big time.
>>>>> Some things that I don’t think can be changed with CSS:
>>>>> 1) texts
>>>>> 2) order of buttons
>>>>> 3) escape characters for shortcuts
>>>>> 4) menus
>>>>> 5) system-level stuff (double-clicking on files, dropping files on
>>>>> applications, …)
>>>>> 6) filesystem conventions
>>>>> 7) ...
>>>>> I think FXML can fix some of these, but not all. So it seems to me
>> that a
>>>>> LaF in JFX will consist of at least:
>>>>>       - one or more CSS files
>>>>>       - one or more FXML files
>>>>>       - some plumbing at the system level
>>>>> It would be nice to have a set of proper LaFs for each major platform
>>>> with
>>>>> an appropriate common API.
>>>>> Steve
>>>>>> On 9 Dec 2013, at 00:20, Jasper Potts <jasper.potts at oracle.com>
>> wrote:
>>>>>> You can set skin classes from CSS so should be able to do everything
>>>> you
>>>>> could with Swing and more. With just a CSS file and skins as and when
>>>>> needed.
>>>>>> Jasper
>>>>>>> On Dec 8, 2013, at 3:00 PM, Jonathan Giles <
>> jonathan.giles at oracle.com
>>>>> wrote:
>>>>>>> At present there are no plans to introduce any further API or
>>>>>>> functionality in this area, but if there is something you are wanting
>>>>>>> then you should file feature requests in Jira.
>>>>>>> -- Jonathan
>>>>>>>> On 9/12/2013 11:54 a.m., Pedro Duque Vieira wrote:
>>>>>>>> Hi,
>>>>>>>> Is there any Look and Feel mechanism in place, like the one in
>> Swing?
>>>>> That
>>>>>>>> doesn't appear to exist..
>>>>>>>> Are there any plans to add one? You can only do so much with CSS...
>>>>>>>> Thanks in advance, best regards,
>>>> --
>>>> Pedro Duque Vieira

More information about the openjfx-dev mailing list