Page 1 of 2

Setting selected record background color of a listbox

PostPosted: Tue Dec 03, 2019 4:37 pm
by huber
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,

Re: Setting selected record background color of a listbox

PostPosted: Mon Dec 09, 2019 9:18 am
by huber
I am thankful for anyone having a hint about styling the background of a listbox in Smart Client.

Regards,

Re: Setting selected record background color of a listbox

PostPosted: Fri Mar 27, 2020 12:36 pm
by huber
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,

Re: Setting selected record background color of a listbox

PostPosted: Mon Mar 30, 2020 11:25 am
by Andrei Costescu
Are you talking here about a list view form with records from a foundset or about a radio/check listbox component?

Re: Setting selected record background color of a listbox

PostPosted: Mon Mar 30, 2020 11:34 am
by huber
I am talking about a list view form (table view (locked)) with records from a foundset.

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

Re: Setting selected record background color of a listbox

PostPosted: Mon Mar 30, 2020 11:49 am
by ROCLASI
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
Code: Select all
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:
Code: Select all
odd {
   background-color: #f5f8fb;
   color: #000000;
}

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


Hope this helps.

Re: Setting selected record background color of a listbox

PostPosted: Mon Mar 30, 2020 3:18 pm
by huber
Hi Robert

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

Best regards,

Re: Setting selected record background color of a listbox

PostPosted: Mon Mar 30, 2020 4:57 pm
by ROCLASI
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.

Re: Setting selected record background color of a listbox

PostPosted: Mon Mar 30, 2020 5:11 pm
by huber
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,

Re: Setting selected record background color of a listbox

PostPosted: Tue Mar 31, 2020 1:50 pm
by Andrei Costescu
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:

listBoxInTableView.png
listBoxInTableView.png (9.08 KiB) Viewed 7227 times

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 :) ):

listBoxInListView.png
listBoxInListView.png (13.64 KiB) Viewed 7227 times

Guess that table view (locked) was just a typo.

Re: Setting selected record background color of a listbox

PostPosted: Wed Apr 01, 2020 3:58 pm
by huber
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,

Re: Setting selected record background color of a listbox

PostPosted: Thu Apr 02, 2020 11:10 am
by 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?

Re: Setting selected record background color of a listbox

PostPosted: Thu Apr 02, 2020 3:42 pm
by huber
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 wrote: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?

Re: Setting selected record background color of a listbox

PostPosted: Thu Apr 02, 2020 4:23 pm
by Andrei Costescu
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.

Re: Setting selected record background color of a listbox

PostPosted: Thu Apr 02, 2020 4:34 pm
by huber
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,