예제 #1
0
    CompletionPopup(String[] actions) {
      super(view);

      setContentPane(
          new JPanel(new BorderLayout()) {

            public boolean isManagingFocus() {
              return false;
            }

            public boolean getFocusTraversalKeysEnabled() {
              return false;
            }
          });

      list = new CompletionList(actions);
      list.setVisibleRowCount(8);
      list.addMouseListener(new MouseHandler());
      list.setSelectedIndex(0);
      list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      JScrollPane scroller =
          new JScrollPane(
              list,
              ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
              ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

      getContentPane().add(scroller, BorderLayout.CENTER);

      GUIUtilities.requestFocus(this, list);

      pack();
      Point p = new Point(0, -getHeight());
      SwingUtilities.convertPointToScreen(p, action);
      setLocation(p);
      setVisible(true);

      KeyHandler keyHandler = new KeyHandler();
      addKeyListener(keyHandler);
      list.addKeyListener(keyHandler);
    }
예제 #2
0
 void setModel(String[] actions) {
   list.setListData(actions);
   list.setSelectedIndex(0);
 }