Using the application.setUIProperty

As you can see in my postings, L&F, skins and UI-properties are keeping me busy.

I’ve found in the manual the application.setUIProperty:

Sets the template directory skin property when deployed to Servoy Web Client; can
be used to set javax.swing.UIDefaults properties when deployed to Servoy Smart
Client; the function must be called as part of the on open method selected in the
Solution Settings dialog.

// setting a UIDefault property for Servoy Smart Client
application.setUIProperty(“ToolTip.hideAccelerator”, true);

So I did like described in the manual. I created a global method onOpenSolution:

application.setUIProperty('Button.background', application.showColorChooser())
application.setUIProperty('Button.foreground', application.showColorChooser())
application.setUIProperty('Button.font', application.showFontChooser())

And on my form I’ve put a button that shows the elementtype:

application.output(elements.myButton.getElementType())

It returns 'BUTTON" as expected. So it is a button.

On open of the solution the application asks for the colors and font, but my button doesn’t have the expected foreground, background and font.

Am I doing something wrong?
I’m not using any specific L&F (is standard) or skin or style.
And of course I using the smart client (I tested client and developer)

application.setUIProperty('Button.background', application.showColorChooser())
```Are you sure that this is correct?
Imho you are calling the colorChooser and not setting a color...

This doesn’t work either:

application.setUIProperty('Button.background', '#FF00FF')
application.setUIProperty('Button.foreground', '#70FF30')

and what when you use a java color like this: ```
java.awt.Color.RED

and what when you use a java color like this: Code:
java.awt.Color.RED

No effect

application.setUIProperty('Button.background', java.awt.Color.RED)
application.setUIProperty('Button.foreground', java.awt.Color.RED)

Hmm, and no further explanation in the docs?

In that case I have run out of ideas…

Well, You’re doing Java now, so you at least need to supply Java objects:
Button is a Servoy object, not a Swing object.

And have you tried to put “java.awt.Color.RED” into a variable and see what kind of object is created? Seems to me you at least need to add “Packages.” in front of it.

Paul

Or maybe ‘new’ ?

application.setUIProperty('Button.background', new java.awt.Color.RED) 

No need to add new in this case.
Color.RED is a static variable.
You only need ‘new’ when you create a new instance…

With or without the new, it still doesn’t work

Am I using the setUIProperty like I should or am I completely wrong?

It is hard to give my solution a personal touch.
I tried the SkinLF but that isn’t working either.
So that is why I thought perhaps the setUIProperty could help me

We where to strict in allowing setting properties, it will be loosened up in Servoy 3.5.4

This is working now in version 3.5.4:

application.setUIProperty('Button.background', new java.awt.Color(0xff00ff))
application.setUIProperty('Button.foreground', new java.awt.Color(0x70ff30))

I expected that the following would work also, but that is not the case:

application.setUIProperty('Button.background', new java.awt.Color(255, 0, 255))
application.setUIProperty('Button.foreground', new java.awt.Color(112, 255, 48))

This is what happens if you start to use Java in Servoy :wink:. From what I see in java.awt.Color there is (among other constructors) this:

Color(float r, float g, float b)
Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0).
Color(int r, int g, int b)
Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255).

Your problem now is that your 255 arrives in Java as a Double, not an int. So you end up in the first constructor, where, of course, your figures are out of range. So you need to create a Java int first…

I’m not familiar with Java and I don’t want to neither :-)
So the 0xff00ff solutions is good enough already.
That troubles with different types I’ve seen Jasper Reports also.
That’s why I don’t like Jasper (even when Jasper is better in positioning of fields compared to Crystal Reports)
Also full of type conversions when making some variable or checking some condition. I hate that :evil: