Setting selected record background color of a listbox

Hi All

The background of a selected record in a listbox shows the default operating system color (for example dark blue and white font on macOS Mojave). Is there a way to set the background color of a selected record - in the style sheet or in inline HTML for a Smart Client?

Regards,

I am thankful for anyone having a hint about styling the background of a listbox in Smart Client.

Regards,

No one has a solution for this? Servoy? Is it at all possible to access the background of a selected listbox record?

Thanks for any hint and best regards,

Are you talking here about a list view form with records from a foundset or about a radio/check listbox component?

I am talking about a list view form (table view (locked)) with records from a foundset.

Andrei Costescu:
Are you talking here about a list view form with records from a foundset or about a radio/check listbox component?

Hi Robert

Ah, I am sure the confusion was that a listbox is an actual control (form element). Not a form object.
To set the selected color on a list/table view you can use (global) CSS for this

selected {
	background-color: #C3C7D1;
	color: #000000;
}

This CSS sample will work on any list/table view form.

You can do the same for the odd/even colors like so:

odd {
	background-color: #f5f8fb;
	color: #000000;
}

even {
	background-color: #FFFFFF;
	color: #000000;
}

Hope this helps.

Hi Robert

Thanks for your answer. The selected {background-color: #C3C7D1;} applies anywhere as expected, except on the LISTBOX.

Best regards,

Hi Robert,

So you ARE talking about the Listbox element type and not about a table/list view form (like in a tabpanel).
I am not sure if there is any CSS for a listbox in SmartClient. Maybe someone from Servoy can answer that.

Sorry for my misreading. To clarify, it’s a field of displayType MULTISELECT_LISTBOX placed on a table view form I am talking, together with other fields, buttons, …

Hope that makes it clear.

Regards,

I am curious how your multiselect listbox in tableview looks like… Are you not using listview (you mentioned table view (locked) before)?

Looking at the code we do set the backgound of multiselect list boxes (on the container/component/renderer and so on).
But a small test with the styling above resulted in this:

[attachment=1]listBoxInTableView.png[/attachment]
So it looks strange being a tableview with a multi-line control in it, but it does seem to take the odd/even/selected styling into account.
And the selected item in the listbox itself has it’s own selection background.

Ahh wait, I tried list view instead of table view and indeed in this case it has a white backgound, because the styling applies to the record’s container and the listbox is not transparent. So if you check “transparent” in properties view it does the trick (I apologise for the ‘screaming’ colors but I added them to be sure they are visible :) ):

[attachment=0]listBoxInListView.png[/attachment]
Guess that table view (locked) was just a typo.

Hi Andrei, and Robert

I have to apologise that I just now realized that I did not mention the listbox is in the title_header part of the (table view) form. Together with the radio buttons (above) and the A B C … X Y Z selection on the bottom. You are absolutely correct that such an element in the table view would be very strange.
I should have realised my omission already when Robert gave feedback. So please excuse me :oops:

I attach a screenshot how it looks like.

What I can’t access is the dark blue selection of the record(s)

Best regards,

Ah that changes the situation quite a bit :). So to make sure I understand now:

  • you don’t care about the background color of the listbox itself
  • you don’t care about odd/even/selected whatever background colors; the white in your screenshot is ok for you
  • you only care about changing the default blue background color of selected items in a listbox.

Is that correct?

Hi Andrei

Yes, your assumption is absolutely correct. I only like to change the default blue background color of selected items in the listbox.

Andrei Costescu:
Ah that changes the situation quite a bit :). So to make sure I understand now:

  • you don’t care about the background color of the listbox itself
  • you don’t care about odd/even/selected whatever background colors; the white in your screenshot is ok for you
  • you only care about changing the default blue background color of selected items in a listbox.

Is that correct?

That cannot easily be done afaik.

If you really must have this, there might be a (quite complicated) way of doing it:

  • create a Servoy plugin (java) with a script method like setSelectionBackgroundForChoiceComp(component). You call that plugin method with your comp. (elements.mylistcomp)
  • the “component” argument that you receive there should be an instance of AbstractRuntimeBaseComponent that has getComponent()
  • that should return a DataChoice that has getEnclosedComponent()
  • that should be a JEditList that has setSelectionForeground() and setSelectionBackground()
  • you can call this new plugin method for all listbox elements that need tweaking when the form is (first) shown.

I didn’t try this but my first impression is that it should do the trick.

Hi Andrei

I had the impression that I could do it with some sort of css styling, but as you mention, the cost of doing it the “complicated” way is a bit too much for me at the moment. Nevertheless I appreciate your idea very much and may be I will come back to it in the future and try it as suggested.

Thanks and best regards,

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:

application.putClientProperty('List.selectionBackground', new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.RED))

[attachment=0]listbox_selection_color.png[/attachment]

Nice. :)
It didn’t occur to me that it can be customized at swing level.

Andrei Costescu:
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 ;)

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,

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/