本文整理匯總了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();
}