本文整理汇总了Java中java.awt.List.select方法的典型用法代码示例。如果您正苦于以下问题:Java List.select方法的具体用法?Java List.select怎么用?Java List.select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.List
的用法示例。
在下文中一共展示了List.select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.List; //导入方法依赖的package包/类
public static void main(final String[] args) throws HeadlessException {
final Frame frame = new Frame("Test Frame");
final List list = new List();
frame.setSize(300, 200);
list.add(ITEM_NAME);
list.select(0);
frame.add(list);
frame.validate();
frame.setVisible(true);
sleep();
if (!ITEM_NAME.equals(list.getSelectedItem())) {
throw new RuntimeException("List item not selected item.");
}
list.removeAll();
frame.dispose();
}
示例2: handleChoice
import java.awt.List; //导入方法依赖的package包/类
protected synchronized void handleChoice(ChoiceCallback c)
{
Frame ownerFrame = new Frame();
Dialog dialog = new Dialog(ownerFrame);
String[] choices = c.getChoices();
dialog.setTitle(c.getPrompt());
Label label = new Label(c.getPrompt());
List list = new List(Math.min(5, choices.length),
c.allowMultipleSelections());
Panel buttons = new Panel();
Button ok = new Button(messages.getString("callback.ok"));
ok.setActionCommand(ACTION_OK);
ok.addActionListener(this);
Button cancel = new Button(messages.getString("callback.cancel"));
cancel.setActionCommand(ACTION_CANCEL);
cancel.addActionListener(this);
for (int i = 0; i < choices.length; i++)
{
list.add(choices[i]);
}
if (c.getDefaultChoice() >= 0 && c.getDefaultChoice() < choices.length)
{
list.select(c.getDefaultChoice());
}
dialog.setLayout(new BorderLayout());
dialog.add(label, BorderLayout.NORTH);
dialog.add(list, BorderLayout.CENTER);
buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
buttons.add(cancel);
buttons.add(ok);
dialog.add(buttons, BorderLayout.SOUTH);
dialog.pack();
dialog.show();
try { wait(); }
catch (InterruptedException ie) { }
if (actionCommand.equals(ACTION_OK))
{
if (c.allowMultipleSelections())
{
c.setSelectedIndexes(list.getSelectedIndexes());
}
else
{
c.setSelectedIndex(list.getSelectedIndex());
}
}
dialog.dispose();
ownerFrame.dispose();
}