Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set style to GWT ListBox items

Is there a way to apply css style to GWT ListBox drop-down menu (ex: change color of some items) I can't do it by setting a style to whole ListBox because i wanna different style for each item! Result will be like that:

<select class="style1" id="test">
  <option class="style2" value="">&nbsp;</option>
  <option class="style2" value="AL">Alabama</option>
  <option class="style6" value="AK">Alaska</option>
  <option class="style6" value="AZ" class="red">Arizona</option>
  <option class="style6" value="AR">Arkansas</option>
  <option value="CA">California</option>
  <option value="CO">Colorado</option>
  <option value="CT">Connecticut</option>
  <option value="DE">Delaware</option>
 </select>
like image 715
Smile2Life Avatar asked Jan 27 '26 23:01

Smile2Life


1 Answers

Try with options.getItem(i).getStyle().setColor("#FF0000");

ListBox listBox = new ListBox();
//Add item to listBox.
SelectElement selectElement = SelectElement.as(listBox.getElement());
NodeList<OptionElement> options = selectElement.getOptions();

for (int i = 0; i < options.getLength(); i++) {
     options.getItem(i).getStyle().setColor("#FF0000");
}
like image 74
Rakesh KR Avatar answered Jan 30 '26 12:01

Rakesh KR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!