Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT ListBox - how to have a listbox item disabled?

Tags:

dom

listbox

gwt

How can I have the first item in a listbox disabled? Following is my code:

ListBox list  = new ListBox();
list.addItem("Select an item");
list.addItem("a");
list.addItem("b");
list.addItem("c");

How do I disable the first item in list? Thanks so much

like image 781
sap Avatar asked Jun 07 '11 18:06

sap


3 Answers

list.getElement().<SelectElement>cast().getOptions().getItem(0).setDisabled(true‌​);
like image 122
Dominator008 Avatar answered Sep 28 '22 08:09

Dominator008


For anyone who finds this page and is looking to disable a GWT ListBox option which is NOT the first option in the ListBox, this worked for me:

list.getElement().getElementsByTagName("option").getItem(itemNumber).setAttribute("disabled", "disabled");

Where itemNumber is the option you would like to disable.

like image 15
KFox112 Avatar answered Oct 16 '22 20:10

KFox112


You could select the first child element and set the disabled atribute:

list.getElement().getFirstChildElement().setAttribute("disabled", "disabled");
like image 8
Andreas Köberle Avatar answered Oct 16 '22 19:10

Andreas Köberle