Setting selected record background color of a listbox

Questions and answers for designing and implementing forms in Servoy

Setting selected record background color of a listbox

Postby huber » Tue Dec 03, 2019 4:37 pm

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,
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 516
Joined: Mon May 14, 2012 11:31 pm

Re: Setting selected record background color of a listbox

Postby huber » Mon Dec 09, 2019 9:18 am

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

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

Re: Setting selected record background color of a listbox

Postby huber » Fri Mar 27, 2020 12:36 pm

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,
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 516
Joined: Mon May 14, 2012 11:31 pm

Re: Setting selected record background color of a listbox

Postby Andrei Costescu » Mon Mar 30, 2020 11:25 am

Are you talking here about a list view form with records from a foundset or about a radio/check listbox component?
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Setting selected record background color of a listbox

Postby huber » Mon Mar 30, 2020 11:34 am

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?
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 516
Joined: Mon May 14, 2012 11:31 pm

Re: Setting selected record background color of a listbox

Postby ROCLASI » Mon Mar 30, 2020 11:49 am

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Setting selected record background color of a listbox

Postby huber » Mon Mar 30, 2020 3:18 pm

Hi Robert

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

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

Re: Setting selected record background color of a listbox

Postby ROCLASI » Mon Mar 30, 2020 4:57 pm

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Setting selected record background color of a listbox

Postby huber » Mon Mar 30, 2020 5:11 pm

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,
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 516
Joined: Mon May 14, 2012 11:31 pm

Re: Setting selected record background color of a listbox

Postby Andrei Costescu » Tue Mar 31, 2020 1:50 pm

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 7158 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 7158 times

Guess that table view (locked) was just a typo.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Setting selected record background color of a listbox

Postby huber » Wed Apr 01, 2020 3:58 pm

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,
Attachments
Screenshot 2020-04-01 at 15.45.54.png
Screenshot 2020-04-01 at 15.45.54.png (18.73 KiB) Viewed 7114 times
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 516
Joined: Mon May 14, 2012 11:31 pm

Re: Setting selected record background color of a listbox

Postby Andrei Costescu » Thu Apr 02, 2020 11:10 am

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?
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Setting selected record background color of a listbox

Postby huber » Thu Apr 02, 2020 3:42 pm

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?
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 516
Joined: Mon May 14, 2012 11:31 pm

Re: Setting selected record background color of a listbox

Postby Andrei Costescu » Thu Apr 02, 2020 4:23 pm

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.
Last edited by Andrei Costescu on Thu Apr 02, 2020 4:37 pm, edited 1 time in total.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Setting selected record background color of a listbox

Postby huber » Thu Apr 02, 2020 4:34 pm

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,
Robert Huber
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
huber
 
Posts: 516
Joined: Mon May 14, 2012 11:31 pm

Next

Return to Forms

Who is online

Users browsing this forum: Google [Bot] and 6 guests

cron