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?
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
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, …
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.
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
I attach a screenshot how it looks like.
What I can’t access is the dark blue selection of the record(s)
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.
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.
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’.
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/