Apache Pivot教程
ListButton,即下拉列表,在HTML里面是<select>标签
ListButton也是Button的成员,可以使用Button类的方法
ListButton有几个独有的方法
void clearSelection();//清除选择项
void setListData(List<>);//设置列表内容
void setListData(String);
void setListData(URL);
int getListSize();
List<> getListData();//获取列表内容
int getSelectedIndex();//获取所选的是列表的第几项,没有选中返回-1,从0开始算
void setSelectedIndex(int);//设置默认选中项
window=new Window();
BoxPane panel=new BoxPane();
ListButton button1=new ListButton();
List<String> list1=new ArrayList<>();
list1.add("hello");
list1.add("hi");
button1.setListData(list1);
button1.setButtonData("please select");
panel.add(button1);
PushButton button2=new PushButton();
button2.setButtonData("clear selection");
button2.getButtonPressListeners().add(new ButtonPressListener()
{
@Override
public void buttonPressed(Button button)
{
button1.clearSelection();
button1.setButtonData("please select");
System.out.println(button1.getListData());
}
});
panel.add(button2);
ListButton button3=new ListButton();
button3.setButtonData("hello");
panel.add(button3);
window.setContent(panel);
window.setTitle("Push Buttons");
window.setMaximized(true);
window.open(display);
如图所示,clearSelection()只是取消选中当前内容,并不会清除列表内容;设置的ButtonData不算选项
那么,如果先选中一个选项,再更改ButtonData,会出现什么情况呢?选中的内容会不会像clearSelection()那样被清除呢?
将源码修改一下再看
window=new Window();
BoxPane panel=new BoxPane();
ListButton button1=new ListButton();
List<String> list1=new ArrayList<>();
list1.add("hello");
list1.add("hi");
button1.setListData(list1);
button1.setButtonData("please select");
panel.add(button1);
PushButton button2=new PushButton();
button2.setButtonData("clear selection");
ListButton button4=new ListButton();
button2.getButtonPressListeners().add(new ButtonPressListener()
{
@Override
public void buttonPressed(Button button)
{
button1.clearSelection();
button1.setButtonData("please select");
System.out.println(button1.getListData());
button4.setButtonData("please select");
System.out.println(button4.getSelectedIndex());
}
});
panel.add(button2);
ListButton button3=new ListButton();
button3.setButtonData("hello");
panel.add(button3);
button4.setButtonData("please select");
button4.setListData(list1);
panel.add(button4);
window.setContent(panel);
window.setTitle("List Buttons");
window.setMaximized(true);
window.open(display);
结果
也就是说,更改了buttondata后对原来的选项没有影响,只是Button显示的信息变了