Java/GWT/ListBox
Версия от 18:01, 31 мая 2010; (обсуждение)
Add item to ListBox
package com.jexp.gwt.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.ListBox;
public class GWTClient implements EntryPoint {
public void onModuleLoad() {
ListBox list = new ListBox();
list.setVisibleItemCount(1);
for (int i = 0; i < 10; ++i) {
list.addItem("list item " + i);
}
RootPanel.get().add(list);
}
}
ListBox with multiple selection
package com.jexp.gwt.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.ListBox;
public class GWTClient implements EntryPoint,ChangeListener {
ListBox list = new ListBox();
public void onModuleLoad() {
list.setVisibleItemCount(10);
list.setMultipleSelect(true);
list.addItem("A");
list.addItem("B");
list.addItem("C");
list.addItem("D");
list.addChangeListener(this);
RootPanel.get().add(list);
}
public void onChange(Widget sender) {
if (sender == list) {
Window.alert(Integer.toString(list.getSelectedIndex()));
}
}
}