Setting selected record background color of a listbox

Questions and answers for designing and implementing forms in Servoy

Re: Setting selected record background color of a listbox

Postby Joas » Tue Apr 07, 2020 5:44 pm

For smartclient you can use application.putClientProperty() to change Swing UI constants.

To change the selection color of the listbox you can use for example:
Code: Select all
application.putClientProperty('List.selectionBackground', new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.RED))

listbox_selection_color.png
listbox_selection_color.png (7.31 KiB) Viewed 309 times
Joas de Haan
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 817
Joined: Mon Mar 20, 2006 4:07 pm
Location: Amersfoort, NL

Re: Setting selected record background color of a listbox

Postby Andrei Costescu » Tue Apr 07, 2020 6:53 pm

Nice. :)
It didn't occur to me that it can be customized at swing level.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 983
Joined: Tue Jun 26, 2007 3:14 pm

Re: Setting selected record background color of a listbox

Postby Joas » Wed Apr 08, 2020 8:49 am

Andrei Costescu wrote:Nice. :)
It didn't occur to me that it can be customized at swing level.

Yes, I think this one ranks pretty high on the list of unknown Servoy features ;)
Joas de Haan
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 817
Joined: Mon Mar 20, 2006 4:07 pm
Location: Amersfoort, NL

Re: Setting selected record background color of a listbox

Postby huber » Wed Apr 08, 2020 9:11 am

Hi Joas

This is great! Exactly what I am looking for. Found, that I can set the color in hex notation like: application.putClientProperty('List.selectionBackground', new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.decode("#ff00ff")));

Of course that stimulates the appetite for more ;-) Where can I find the list of names for the application.putClientProperty like your suggested 'List.selectionBackground'. I also would like to control the height of a (selected) row for example. I could find some examples in the Servoy Docu, but for example not your 'List.selectionBackground'.

Thanks again a lot!

Regards,
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 370
Joined: Mon May 14, 2012 11:31 pm

Re: Setting selected record background color of a listbox

Postby Andrei Costescu » Wed Apr 08, 2020 9:30 am

It depends on the look and feel that is used.
More info (lists for some look and feels, code that would give what is available in your configuration (that could be ported to Servoy) etc.): https://stackoverflow.com/questions/195 ... properties

For example this utility lists them if you run it. I guess if you are using a different look and feel you should change the code to use that in the utility as well: https://tips4java.wordpress.com/2008/10 ... -defaults/
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 983
Joined: Tue Jun 26, 2007 3:14 pm

Re: Setting selected record background color of a listbox

Postby Joas » Wed Apr 08, 2020 9:38 am

Here you have a list: https://thebadprogrammer.com/swing-uimanager-keys/
I don't see a property for the rowheight of the list, but maybe that changes when you change the font.
Joas de Haan
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 817
Joined: Mon Mar 20, 2006 4:07 pm
Location: Amersfoort, NL

Re: Setting selected record background color of a listbox

Postby huber » Wed Apr 08, 2020 10:26 am

Thanks, Joas. Now the only puzzle work is to find the corresponding value to the key. Like for example this works:

Code: Select all
application.putClientProperty('List.selectionForeground', new [code]Packages.javax.swing.plaf.ColorUIResource[/code](java.awt.Color.decode('#ff000')));


whereas these do not work:

Code: Select all
application.putClientProperty('List.evenRowBackgroundPainter', new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.decode('#ff0000')));
application.putClientProperty('List.font', new Packages.javax.swing.plaf.FontUIResource('Tahoma', 0, 11));


Don't see why, though. It would be nice to have such a key values pair list but I assume it does not exist in this form.
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 370
Joined: Mon May 14, 2012 11:31 pm

Re: Setting selected record background color of a listbox

Postby Andrei Costescu » Wed Apr 08, 2020 11:20 am

Run this method in your solution (the code I linked to above - integrated in Servoy); it will give you the list of property keys and default values that are available in your environment:

Code: Select all
/**
* Lists supported l&f specific UIManager properties. (can be used to customize a bit smart client's look and feel)
*
* @param {JSEvent} event the event that triggered the action
*
* @properties={typeid:24,uuid:"ED567DF9-DDF1-49AD-9CA6-4A361013FBF4"}
*/
function listUIManagerProperties(event) {
    var defaults = Packages.javax.swing.UIManager.getDefaults();
    application.output(defaults.size()+ " properties defined !");
    application.output("Key                                                                   Value");
    application.output("");

    var e = defaults.keys();
    var output = [];
    while (e.hasMoreElements()) {
        var key = e.nextElement();
        var str = key;
        for (var j = 0; j < 70 - key.length; j++) str += " ";
        str += "" + defaults.get(key);
        output.push(str);
    }

    output.sort();
    output.forEach(function(x) { application.output(x) });
}

I suspect that those two properties (or at least one) that you were trying to use are available in other look-and-feel implementations, not in the one you now have.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 983
Joined: Tue Jun 26, 2007 3:14 pm

Re: Setting selected record background color of a listbox

Postby huber » Thu Apr 09, 2020 10:55 am

Hi Andrei

Thanks for your script, very helpful. I executed the script and it shows as you say the key value pairs. For example I get the following pairs (just as typical examples):

List.noFocusBorder javax.swing.plaf.BorderUIResource$EmptyBorderUIResource@6880b3da
List.selectionInactiveBackground com.apple.laf.AquaImageFactory$SystemColorProxy[r=212,g=212,b=212]

I tried to use them but in the first case i'ts a problem with the @6880b3da part (seems to be a reference) and on the second Servoy Developer says variable not declared (it's the r=) removing it does not help either.
On the second I also use it in the form with new Packages.com.apple.laf... May be that's wrong.

application.putClientProperty('List.selectionInactiveBackground', new Packages.com.apple.laf.AquaImageFactory$SystemColorProxy[212,212,212]);

As a side note, in the script, I get an error for the key.length saying property length is undefined

Thanks again for your support, very appreciated :-)
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 370
Joined: Mon May 14, 2012 11:31 pm

Re: Setting selected record background color of a listbox

Postby huber » Thu Apr 09, 2020 11:35 am

May be the format should be something like this:

application.putClientProperty('List.noFocusBorder', new Packages.javax.swing.plaf.BorderUIResource.EmptyBorderUIResource(0, 0, 0, 0));

No errors any more, but I am not sure now what it should do. Thought it was the dotted line around the selected text in the row selected, but it does not seem to be that.
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 370
Joined: Mon May 14, 2012 11:31 pm

Re: Setting selected record background color of a listbox

Postby Andrei Costescu » Thu Apr 09, 2020 12:50 pm

Yes, that is the tough part - getting what all of them are for and what values you can put there (for non-basic types with self-explaining names).
If you want to get into details about all those options then you either have to find some look and feel specific docs about them or look at the source code (if it's public) to figure out those things.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 983
Joined: Tue Jun 26, 2007 3:14 pm

Previous

Return to Forms

Who is online

Users browsing this forum: No registered users and 9 guests

cron