Java 类javax.swing.plaf.basic.ComboPopup 实例源码

项目:swing-material    文件:MaterialComboBox.java   
public MaterialComboBox() {
    setModel(new DefaultComboBoxModel<T>());
    setRenderer(new FieldRenderer<T>(this));
    setUI(new BasicComboBoxUI() {
        @Override
        protected ComboPopup createPopup() {
            BasicComboPopup popup = new Popup(comboBox);
            popup.getAccessibleContext().setAccessibleParent(comboBox);
            return popup;
        }

        @Override
        protected JButton createArrowButton() {
            JButton button = new javax.swing.plaf.basic.BasicArrowButton(
                    javax.swing.plaf.basic.BasicArrowButton.SOUTH,
                    MaterialColor.TRANSPARENT,
                    MaterialColor.TRANSPARENT,
                    MaterialColor.TRANSPARENT,
                    MaterialColor.TRANSPARENT);
            button.setName("ComboBox.arrowButton");
            return button;
        }
    });
    setOpaque(false);
    setBackground(MaterialColor.TRANSPARENT);
}
项目:javify    文件:JComboBox.java   
/**
 * Returns the accessible selection from this AccssibleJComboBox.
 *
 * @param index the index of the selected child to fetch
 *
 * @return the accessible selection from this AccssibleJComboBox
 */
public Accessible getAccessibleSelection(int index)
{
  // Get hold of the actual popup.
  Accessible popup = getUI().getAccessibleChild(JComboBox.this, 0);
  Accessible selected = null;
  if (popup != null && popup instanceof ComboPopup)
    {
      ComboPopup cPopup = (ComboPopup) popup;
      // Query the list for the currently selected child.
      JList l = cPopup.getList();
      AccessibleContext listCtx = l.getAccessibleContext();
      if (listCtx != null)
        {
          AccessibleSelection s = listCtx.getAccessibleSelection();
          if (s != null)
            {
              selected = s.getAccessibleSelection(index);
            }
        }
    }
  return selected;
}
项目:Stud.IP-Client    文件:DropDownBox.java   
@Override
protected ComboPopup createPopup() {
    return new BasicComboPopup(comboBox) {
        private static final long serialVersionUID = -1460253465809092623L;

        @Override
        protected void configurePopup() {
            setBorderPainted(true);
            setBorder(BorderFactory.createLineBorder(Template.COLOR_LIGHT_GRAY));
            setOpaque(false);
            add(scroller);
            setFocusable(false);
        }

    };

}
项目:jvm-stm    文件:JComboBox.java   
/**
 * Returns the accessible selection from this AccssibleJComboBox.
 *
 * @param index the index of the selected child to fetch
 *
 * @return the accessible selection from this AccssibleJComboBox
 */
public Accessible getAccessibleSelection(int index)
{
  // Get hold of the actual popup.
  Accessible popup = getUI().getAccessibleChild(JComboBox.this, 0);
  Accessible selected = null;
  if (popup != null && popup instanceof ComboPopup)
    {
      ComboPopup cPopup = (ComboPopup) popup;
      // Query the list for the currently selected child.
      JList l = cPopup.getList();
      AccessibleContext listCtx = l.getAccessibleContext();
      if (listCtx != null)
        {
          AccessibleSelection s = listCtx.getAccessibleSelection();
          if (s != null)
            {
              selected = s.getAccessibleSelection(index);
            }
        }
    }
  return selected;
}
项目:cn1    文件:MetalComboBoxUITest.java   
public void testGetMinimumSize() throws Exception {
    ui.setComboBox(comboBox);
    ComboPopup popup = new BasicComboPopup(comboBox);
    ui.setPopup(popup);
    ui.setListBox(popup.getList());
    ui.installListeners();
    comboBox.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    Dimension listPart = new BasicComboBoxRenderer().getListCellRendererComponent(
            popup.getList(), "", -1, false, false).getPreferredSize();
    Dimension expectedSize = new Dimension(listPart.width + listPart.height + 8,
            listPart.height + 8);
    assertEquals(expectedSize, ui.getMinimumSize(null));
    assertEquals(expectedSize, ui.getCachedMinimumSize());
    ui.setCachedMinimumSize(new Dimension(100, 100));
    assertEquals(ui.getCachedMinimumSize(), ui.getMinimumSize(null));
    comboBox.addItem("aaa");
    listPart = new BasicComboBoxRenderer().getListCellRendererComponent(popup.getList(),
            "aaa", -1, false, false).getPreferredSize();
    expectedSize = new Dimension(listPart.width + listPart.height + 8, listPart.height + 8);
    assertEquals(expectedSize, ui.getMinimumSize(null));
}
项目:JamVM-PH    文件:JComboBox.java   
/**
 * Returns the accessible selection from this AccssibleJComboBox.
 *
 * @param index the index of the selected child to fetch
 *
 * @return the accessible selection from this AccssibleJComboBox
 */
public Accessible getAccessibleSelection(int index)
{
  // Get hold of the actual popup.
  Accessible popup = getUI().getAccessibleChild(JComboBox.this, 0);
  Accessible selected = null;
  if (popup != null && popup instanceof ComboPopup)
    {
      ComboPopup cPopup = (ComboPopup) popup;
      // Query the list for the currently selected child.
      JList l = cPopup.getList();
      AccessibleContext listCtx = l.getAccessibleContext();
      if (listCtx != null)
        {
          AccessibleSelection s = listCtx.getAccessibleSelection();
          if (s != null)
            {
              selected = s.getAccessibleSelection(index);
            }
        }
    }
  return selected;
}
项目:breakout    文件:JComboBoxFixture.java   
public static String readText(final JComboBox cb, final int index) {
    return new DoSwingR<String>() {
        @Override
        protected String doRun() {
            Object value = cb.getItemAt(index);
            try {
                BasicComboBoxUI ui = (BasicComboBoxUI) cb.getUI();
                Field popupField = ReflectionUtils.getField(ui.getClass(), "popup");
                popupField.setAccessible(true);
                ComboPopup popup = (ComboPopup) popupField.get(ui);
                JList list = popup.getList();
                ListCellRenderer renderer = list.getCellRenderer();
                Component rendComp = renderer.getListCellRendererComponent(popup.getList(), value, index, false,
                        false);
                return ComponentFixture.Common.readText(rendComp);
            } catch (Exception ex) {
            }
            return value.toString();
        }
    }.result();
}
项目:IBMDataMovementTool    文件:MenuSelectionProcessor.java   
private void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if (path.length > 0) { // we are in a combo box
        menuCanceledOnPress = false;
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        JMenuBar mbar = getMenuBar(ev);
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if (menu != null) {
            ev.consume();
        }
    }
}
项目:classpath    文件:JComboBox.java   
/**
 * Returns the accessible selection from this AccssibleJComboBox.
 *
 * @param index the index of the selected child to fetch
 *
 * @return the accessible selection from this AccssibleJComboBox
 */
public Accessible getAccessibleSelection(int index)
{
  // Get hold of the actual popup.
  Accessible popup = getUI().getAccessibleChild(JComboBox.this, 0);
  Accessible selected = null;
  if (popup != null && popup instanceof ComboPopup)
    {
      ComboPopup cPopup = (ComboPopup) popup;
      // Query the list for the currently selected child.
      JList l = cPopup.getList();
      AccessibleContext listCtx = l.getAccessibleContext();
      if (listCtx != null)
        {
          AccessibleSelection s = listCtx.getAccessibleSelection();
          if (s != null)
            {
              selected = s.getAccessibleSelection(index);
            }
        }
    }
  return selected;
}
项目:freeVM    文件:MetalComboBoxUITest.java   
public void testGetMinimumSize() throws Exception {
    ui.setComboBox(comboBox);
    ComboPopup popup = new BasicComboPopup(comboBox);
    ui.setPopup(popup);
    ui.setListBox(popup.getList());
    ui.installListeners();
    comboBox.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    Dimension listPart = new BasicComboBoxRenderer().getListCellRendererComponent(
            popup.getList(), "", -1, false, false).getPreferredSize();
    Dimension expectedSize = new Dimension(listPart.width + listPart.height + 8,
            listPart.height + 8);
    assertEquals(expectedSize, ui.getMinimumSize(null));
    assertEquals(expectedSize, ui.getCachedMinimumSize());
    ui.setCachedMinimumSize(new Dimension(100, 100));
    assertEquals(ui.getCachedMinimumSize(), ui.getMinimumSize(null));
    comboBox.addItem("aaa");
    listPart = new BasicComboBoxRenderer().getListCellRendererComponent(popup.getList(),
            "aaa", -1, false, false).getPreferredSize();
    expectedSize = new Dimension(listPart.width + listPart.height + 8, listPart.height + 8);
    assertEquals(expectedSize, ui.getMinimumSize(null));
}
项目:freeVM    文件:MetalComboBoxUITest.java   
public void testGetMinimumSize() throws Exception {
    ui.setComboBox(comboBox);
    ComboPopup popup = new BasicComboPopup(comboBox);
    ui.setPopup(popup);
    ui.setListBox(popup.getList());
    ui.installListeners();
    comboBox.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    Dimension listPart = new BasicComboBoxRenderer().getListCellRendererComponent(
            popup.getList(), "", -1, false, false).getPreferredSize();
    Dimension expectedSize = new Dimension(listPart.width + listPart.height + 8,
            listPart.height + 8);
    assertEquals(expectedSize, ui.getMinimumSize(null));
    assertEquals(expectedSize, ui.getCachedMinimumSize());
    ui.setCachedMinimumSize(new Dimension(100, 100));
    assertEquals(ui.getCachedMinimumSize(), ui.getMinimumSize(null));
    comboBox.addItem("aaa");
    listPart = new BasicComboBoxRenderer().getListCellRendererComponent(popup.getList(),
            "aaa", -1, false, false).getPreferredSize();
    expectedSize = new Dimension(listPart.width + listPart.height + 8, listPart.height + 8);
    assertEquals(expectedSize, ui.getMinimumSize(null));
}
项目:incubator-netbeans    文件:ComboBoxAutoCompleteSupport.java   
private static JList getPopupList( JComboBox combo ) {
    Accessible a = combo.getUI().getAccessibleChild(combo, 0);

    if( a instanceof ComboPopup ) {
        return ((ComboPopup) a).getList();
    }
    return null;
}
项目:incubator-netbeans    文件:ComboBoxAutoCompleteSupport.java   
private static JList getPopupList( JComboBox combo ) {
    Accessible a = combo.getUI().getAccessibleChild(combo, 0);

    if( a instanceof ComboPopup ) {
        return ((ComboPopup) a).getList();
    }
    return null;
}
项目:jmt    文件:SteppedComboBoxUI.java   
@Override
protected ComboPopup createPopup() {
    BasicComboPopup popup = new BasicComboPopup(comboBox) {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void show() {
            Dimension popupSize = ((SteppedComboBox) comboBox).getPopupSize();
            popupSize.setSize(popupSize.width, getPopupHeightForRowCount(comboBox.getMaximumRowCount()));
            Rectangle popupBounds = computePopupBounds(0, comboBox.getBounds().height, popupSize.width, popupSize.height);
            scroller.setMaximumSize(popupBounds.getSize());
            scroller.setPreferredSize(popupBounds.getSize());
            scroller.setMinimumSize(popupBounds.getSize());
            list.invalidate();
            int selectedIndex = comboBox.getSelectedIndex();
            if (selectedIndex == -1) {
                list.clearSelection();
            } else {
                list.setSelectedIndex(selectedIndex);
            }
            list.ensureIndexIsVisible(list.getSelectedIndex());
            setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled());

            show(comboBox, popupBounds.x, popupBounds.y);
        }
    };
    popup.getAccessibleContext().setAccessibleParent(comboBox);
    return popup;
}
项目:QN-ACTR-Release    文件:SteppedComboBoxUI.java   
@Override
protected ComboPopup createPopup() {
    BasicComboPopup popup = new BasicComboPopup(comboBox) {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void show() {
            Dimension popupSize = ((SteppedComboBox) comboBox).getPopupSize();
            popupSize.setSize(popupSize.width, getPopupHeightForRowCount(comboBox.getMaximumRowCount()));
            Rectangle popupBounds = computePopupBounds(0, comboBox.getBounds().height, popupSize.width, popupSize.height);
            scroller.setMaximumSize(popupBounds.getSize());
            scroller.setPreferredSize(popupBounds.getSize());
            scroller.setMinimumSize(popupBounds.getSize());
            list.invalidate();
            int selectedIndex = comboBox.getSelectedIndex();
            if (selectedIndex == -1) {
                list.clearSelection();
            } else {
                list.setSelectedIndex(selectedIndex);
            }
            list.ensureIndexIsVisible(list.getSelectedIndex());
            setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled());

            show(comboBox, popupBounds.x, popupBounds.y);
        }
    };
    popup.getAccessibleContext().setAccessibleParent(comboBox);
    return popup;
}
项目:OpenJSharp    文件:WindowsRootPaneUI.java   
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
项目:jdk8u-jdk    文件:WindowsRootPaneUI.java   
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
项目:openjdk-jdk10    文件:WindowsRootPaneUI.java   
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
项目:openjdk-jdk10    文件:JComboBoxOperator.java   
public ListWater() {
    super();
    cChooser = new ComponentChooser() {
        @Override
        public boolean checkComponent(Component comp) {
            if (comp instanceof JList) {
                Container cont = (Container) comp;
                while ((cont = cont.getParent()) != null) {
                    if (cont instanceof ComboPopup) {
                        return true;
                    }
                }
            }
            return false;
        }

        @Override
        public String getDescription() {
            return "Popup menu";
        }

        @Override
        public String toString() {
            return "JComboBoxOperator.ListWater.ComponentChooser{description = " + getDescription() + '}';
        }
    };
    pChooser = new PopupWindowChooser(cChooser);
}
项目:openjdk9    文件:WindowsRootPaneUI.java   
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
项目:openjdk9    文件:JComboBoxOperator.java   
public ListWater() {
    super();
    cChooser = new ComponentChooser() {
        @Override
        public boolean checkComponent(Component comp) {
            if (comp instanceof JList) {
                Container cont = (Container) comp;
                while ((cont = cont.getParent()) != null) {
                    if (cont instanceof ComboPopup) {
                        return true;
                    }
                }
            }
            return false;
        }

        @Override
        public String getDescription() {
            return "Popup menu";
        }

        @Override
        public String toString() {
            return "JComboBoxOperator.ListWater.ComponentChooser{description = " + getDescription() + '}';
        }
    };
    pChooser = new PopupWindowChooser(cChooser);
}
项目:workcraft    文件:FlatComboBox.java   
@Override
protected ComboPopup createPopup() {
    BasicComboPopup popup = new BasicComboPopup(comboBox) {
        @Override
        protected Rectangle computePopupBounds(int px, int py, int pw, int ph) {
            return super.computePopupBounds(px, py, Math.max(comboBox.getPreferredSize().width, pw), ph);
        }
    };
    popup.getAccessibleContext().setAccessibleParent(comboBox);
    return popup;
}
项目:Empire-Earth---DB-Editor    文件:JComboBoxField.java   
@Override
public void focusLost (FocusEvent e) {
    ComboPopup cp = (ComboPopup) getUI().getAccessibleChild(JComboBoxField.this, 0);
    Object item = null;
    item = cp.getList().getSelectedValue();
    if (item == null){
        item = searcher.getCurrent();
    }
    if (item != null){
        setSelectedItem(item);
    }
}
项目:jdk8u_jdk    文件:WindowsRootPaneUI.java   
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:WindowsRootPaneUI.java   
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
项目:LS-jsampler    文件:FantasiaComboBoxUI.java   
@Override
protected ComboPopup
createPopup() {
    ComboPopup cp = new SubstanceComboPopup(combo);
    cp.getList().setFont(cp.getList().getFont().deriveFont(10.0f));

    return cp;
}
项目:intellij-ce-playground    文件:DebuggerExpressionComboBox.java   
@Nullable
public Object getCurrentPopupValue() {
  if (!isPopupVisible()) return null;

  final ComboPopup popup = myComboBox.getPopup();
  if (popup != null) {
    return popup.getList().getSelectedValue();
  }

  return null;
}
项目:intellij-ce-playground    文件:FixedComboBoxEditor.java   
@Nullable
private static ComboPopup getComboboxPopup(final JComboBox comboBox) {
  final ComboBoxUI ui = comboBox.getUI();
  ComboPopup popup = null;
  if (ui instanceof BasicComboBoxUI) {
    popup = ReflectionUtil.getField(BasicComboBoxUI.class, ui, ComboPopup.class, "popup");
  }

  return popup;
}
项目:intellij-ce-playground    文件:FixedComboBoxEditor.java   
private void textChanged() {
  final Container ancestor = SwingUtilities.getAncestorOfClass(JComboBox.class, this);
  if (ancestor == null || !ancestor.isVisible()) return;

  final JComboBox comboBox = (JComboBox)ancestor;
  if (!comboBox.isPopupVisible()) return;

  final ComboPopup popup = getComboboxPopup(comboBox);
  if (popup == null) return;

  String s = myField.getText();

  final ListModel listmodel = comboBox.getModel();
  int i = listmodel.getSize();
  if (s.length() > 0) {
    for (int j = 0; j < i; j++) {
      Object obj = listmodel.getElementAt(j);
      if (obj == null) continue;

      String s1 = obj.toString();
      if (s1 != null && (s1.startsWith(s) || s1.equals(s))) {
        popup.getList().setSelectedIndex(j);
        return;
      }
    }
  }

  popup.getList().clearSelection();
}
项目:intellij-ce-playground    文件:UIUtil.java   
@Nullable
public static ComboPopup getComboBoxPopup(@NotNull JComboBox comboBox) {
  final ComboBoxUI ui = comboBox.getUI();
  if (ui instanceof BasicComboBoxUI) {
    return ReflectionUtil.getField(BasicComboBoxUI.class, ui, ComboPopup.class, "popup");
  }

  return null;
}
项目:intellij-ce-playground    文件:XDebuggerTreeInplaceEditor.java   
@Override
protected void onHidden() {
  final ComboPopup popup = myExpressionEditor.getComboBox().getPopup();
  if (popup != null && popup.isVisible()) {
    popup.hide();
  }
}
项目:intellij-ce-playground    文件:ResourceEditor.java   
public MyComboBox() {
  ((JTextField)getEditor().getEditorComponent()).addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      if (isPopupVisible()) {
        ComboPopup popup = getPopup();
        if (popup != null) {
          setSelectedItem(popup.getList().getSelectedValue());
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:GradleEditorComboBoxEditor.java   
private void textChanged() {
  final Container ancestor = SwingUtilities.getAncestorOfClass(JComboBox.class, this);
  if (ancestor == null || !ancestor.isVisible()) return;

  final JComboBox comboBox = (JComboBox)ancestor;
  if (!comboBox.isPopupVisible()) return;

  final ComboPopup popup = getComboboxPopup(comboBox);
  if (popup == null) return;

  String s = myField.getText();

  final ListModel listmodel = comboBox.getModel();
  int i = listmodel.getSize();
  if (s.length() > 0) {
    for (int j = 0; j < i; j++) {
      Object obj = listmodel.getElementAt(j);
      if (obj == null) continue;

      String s1 = obj.toString();
      if (s1 != null && (s1.startsWith(s) || s1.equals(s))) {
        popup.getList().setSelectedIndex(j);
        return;
      }
    }
  }

  popup.getList().clearSelection();
}
项目:swingx    文件:ComboBoxAdaptor.java   
@Override
public void setSelectedItem(Object item) {
    //SwingX 834: avoid moving when already selected
    if (item == getSelectedItem()) {
        return;
    }

    // kgs - back door our way to finding the JList that displays the data.
    // then we ask the list to scroll until the last cell is visible. this
    // will cause the selected item to appear closest to the top.
    //
    // it is unknown whether this functionality will work outside of Sun's
    // implementation, but the code is safe and will "fail gracefully" on
    // other systems
    Accessible a = comboBox.getUI().getAccessibleChild(comboBox, 0);

    if (getItemCount() > 0 && a instanceof ComboPopup) {
        JList list = ((ComboPopup) a).getList();
        int lastIndex = list.getModel().getSize() - 1;

        Rectangle rect = list.getCellBounds(lastIndex, lastIndex);

        if (rect == null) {
            throw new IllegalStateException(
                    "attempting to access index " + lastIndex + " for " + comboBox);
        }

        list.scrollRectToVisible(rect);
    }

    //setting the selected item should scroll it into the visible region
    comboBox.setSelectedItem(item);
}
项目:swingx    文件:JXComboBox.java   
protected static JList getPopupListFor(JComboBox comboBox) {
    int count = comboBox.getUI().getAccessibleChildrenCount(comboBox);

    for (int i = 0; i < count; i++) {
        Accessible a = comboBox.getUI().getAccessibleChild(comboBox, i);

        if (a instanceof ComboPopup) {
            return ((ComboPopup) a).getList();
        }
    }

    return null;
}
项目:WorldGrower    文件:JComboBoxFactory.java   
private static<T> void setComboBoxProperties(JComboBox<T> comboBox, ImageInfoReader imageInfoReader) {
    comboBox.setOpaque(false);
    comboBox.setBackground(ColorPalette.FOREGROUND_COLOR);
    comboBox.setForeground(ColorPalette.FOREGROUND_COLOR);
    comboBox.setFont(Fonts.FONT);

    comboBox.setUI(new MetalComboBoxUI() {

        @Override
        protected ComboPopup createPopup() {
            return new TiledImageComboPopup( comboBox, imageInfoReader );
        }
    });
}
项目:metasfresh    文件:AdempiereComboBoxUI.java   
/**
 * Create Popup
 * 
 * @return {@link AdempiereComboPopup}
 */
@Override
protected ComboPopup createPopup()
{
    final AdempiereComboPopup popup = new AdempiereComboPopup(comboBox);
    popup.getAccessibleContext().setAccessibleParent(comboBox);
    return popup;
}
项目:metasfresh    文件:AdempiereComboBoxUI.java   
public static final ComboPopup getComboPopup(final JComboBox<?> comboBox)
{
    final ComboBoxUI comboBoxUI = comboBox.getUI();
    if (comboBoxUI instanceof AdempiereComboBoxUI)
    {
        return ((AdempiereComboBoxUI)comboBoxUI).getComboPopup();
    }

    //
    // Fallback:
    // Back door our way to finding the inner JList.
    //
    // it is unknown whether this functionality will work outside of Sun's
    // implementation, but the code is safe and will "fail gracefully" on
    // other systems
    //
    // see javax.swing.plaf.basic.BasicComboBoxUI.getAccessibleChild(JComponent, int)
    final Accessible a = comboBoxUI.getAccessibleChild(comboBox, 0);
    if (a instanceof ComboPopup)
    {
        return (ComboPopup)a;
    }
    else
    {
        return null;
    }
}
项目:metasfresh    文件:ComboBoxAutoCompletion.java   
/** @return combobox's inner JList (if available) */
private final JList<E> getJList()
{
    final ComboPopup comboPopup = AdempiereComboBoxUI.getComboPopup(comboBox);
    if (comboPopup == null)
    {
        return null;
    }

    @SuppressWarnings("unchecked")
    final JList<E> list = comboPopup.getList();
    return list;
}
项目:SmartTokens    文件:HudComboBoxUI.java   
@Override
protected ComboPopup createPopup() {
    EPComboPopup popup = new EPComboPopup(comboBox);
    popup.setFont(HudPaintingUtils.getHudFont().deriveFont(Font.PLAIN));
    // install a custom ComboBoxVerticalCenterProvider that takes into account the size of the
    // drop shadow.
    popup.setVerticalComponentCenterProvider(createComboBoxVerticalCenterProvider());
    return popup;
}