當前位置: 首頁>>代碼示例>>Java>>正文


Java List.select方法代碼示例

本文整理匯總了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();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:R2303044ListSelection.java

示例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();
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:50,代碼來源:AWTCallbackHandler.java


注:本文中的java.awt.List.select方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。