Java Code Examples for javax.swing.plaf.basic.ComboPopup

The following examples show how to use javax.swing.plaf.basic.ComboPopup. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xdm   Source File: XDMComboBoxUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected ComboPopup createPopup() {
	return new BasicComboPopup(comboBox) {
		/**
		 * 
		 */
		private static final long serialVersionUID = -4232501153552563408L;

		@Override
		protected JScrollPane createScroller() {
			JScrollPane scroller = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
					JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
			scroller.setVerticalScrollBar(new DarkScrollBar(JScrollBar.VERTICAL));
			return scroller;
		}
	};
}
 
Example 2
@Override
protected ComboPopup createPopup() {
    final SubstanceComboPopup sPopup = new SubstanceComboPopup(this.comboBox);
    final ComponentOrientation currOrientation = this.comboBox.getComponentOrientation();

    SwingUtilities.invokeLater(() -> {
        if (SubstanceComboBoxUI.this.comboBox == null) {
            return;
        }

        sPopup.applyComponentOrientation(currOrientation);
        sPopup.doLayout();
        ListCellRenderer cellRenderer = SubstanceComboBoxUI.this.comboBox.getRenderer();
        if (cellRenderer instanceof Component) {
            ((Component) cellRenderer).applyComponentOrientation(currOrientation);
        }
        ComboBoxEditor editor = SubstanceComboBoxUI.this.comboBox.getEditor();
        if ((editor != null) && (editor.getEditorComponent() != null)) {
            (editor.getEditorComponent()).applyComponentOrientation(currOrientation);
        }
        SubstanceComboBoxUI.this.comboBox.repaint();
    });
    return sPopup;
}
 
Example 3
Source Project: swing-material   Source File: MaterialComboBox.java    License: MIT License 6 votes vote down vote up
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);
}
 
Example 4
Source Project: jdk1.8-source-analysis   Source File: WindowsRootPaneUI.java    License: Apache License 2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 5
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();
        }
    }
}
 
Example 6
Source Project: jdk8u60   Source File: WindowsRootPaneUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 7
Source Project: JDKSourceCode1.8   Source File: WindowsRootPaneUI.java    License: MIT License 5 votes vote down vote up
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();
        }
    }
}
 
Example 8
Source Project: nanoleaf-desktop   Source File: ModernComboBoxUI.java    License: MIT License 5 votes vote down vote up
@Override
protected ComboPopup createPopup()
{
	return new BasicComboPopup(comboBox)
	{
		@Override
		protected JScrollPane createScroller()
		{
			// Override the default Metal scrollbar
			JScrollPane scroller = super.createScroller();
			scroller.getVerticalScrollBar().setUI(new ModernScrollBarUI());
			return scroller;
		}
	};
}
 
Example 9
@Override
public void installListeners() {
    this.hierarchyListener = (HierarchyEvent e) -> {
        if (jcomp.getParent() instanceof ComboPopup) {
            if (scrollPaneSelector != null) {
                scrollPaneSelector.uninstallFromScrollPane();
                scrollPaneSelector = null;
            }
        }
    };
    this.jcomp.addHierarchyListener(this.hierarchyListener);

    this.propertyChangeListener = (PropertyChangeEvent evt) -> {
        if (SubstanceSynapse.COMPONENT_PREVIEW_PAINTER.equals(evt.getPropertyName())) {
            PreviewPainter pPainter = WidgetUtilities.getComponentPreviewPainter(jcomp);
            // Uninstall old scroll pane selector
            if (scrollPaneSelector != null) {
                scrollPaneSelector.uninstallFromScrollPane();
                scrollPaneSelector = null;
            }
            // Install new scroll pane selector
            if (pPainter != null && SubstanceCoreUtilities.toShowExtraWidgets(jcomp)) {
                scrollPaneSelector = new ScrollPaneSelector();
                scrollPaneSelector.installOnScrollPane(jcomp);
            }
        }
    };
    this.jcomp.addPropertyChangeListener(this.propertyChangeListener);
}
 
Example 10
Source Project: consulo   Source File: XDebuggerTreeInplaceEditor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onHidden() {
  final ComboPopup popup = myExpressionEditor.getComboBox().getPopup();
  if (popup != null && popup.isVisible()) {
    popup.hide();
  }
}
 
Example 11
Source Project: netbeans   Source File: ComboBoxAutoCompleteSupport.java    License: Apache License 2.0 5 votes vote down vote up
private static JList getPopupList( JComboBox combo ) {
    Accessible a = combo.getUI().getAccessibleChild(combo, 0);

    if( a instanceof ComboPopup ) {
        return ((ComboPopup) a).getList();
    }
    return null;
}
 
Example 12
Source Project: netbeans   Source File: ComboBoxAutoCompleteSupport.java    License: Apache License 2.0 5 votes vote down vote up
private static JList getPopupList( JComboBox combo ) {
    Accessible a = combo.getUI().getAccessibleChild(combo, 0);

    if( a instanceof ComboPopup ) {
        return ((ComboPopup) a).getList();
    }
    return null;
}
 
Example 13
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();
        }
    }
}
 
Example 14
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();
        }
    }
}
 
Example 15
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);
}
 
Example 16
Source Project: jdk8u-jdk   Source File: WindowsRootPaneUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 17
Source Project: hottub   Source File: WindowsRootPaneUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 18
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();
        }
    }
}
 
Example 19
Source Project: workcraft   Source File: FlatComboBox.java    License: MIT License 5 votes vote down vote up
@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;
}
 
Example 20
Source Project: openjdk-8   Source File: WindowsRootPaneUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 21
Source Project: consulo   Source File: XDebuggerTreeInplaceEditor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void doPopupOKAction() {
  ComboPopup popup = myExpressionEditor.getComboBox().getPopup();
  if (popup != null && popup.isVisible()) {
    Object value = popup.getList().getSelectedValue();
    if (value != null) {
      myExpressionEditor.setExpression((XExpression)value);
    }
  }
  doOKAction();
}
 
Example 22
Source Project: jdk8u_jdk   Source File: WindowsRootPaneUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 23
Source Project: WorldGrower   Source File: JComboBoxFactory.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 );
		}
	});
}
 
Example 24
Source Project: jdk8u-jdk   Source File: WindowsRootPaneUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 25
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();
        }
    }
}
 
Example 26
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
public static JComboBox<Icon> makeComboBox1(ComboBoxModel<Icon> model, Icon proto, int rowCount) {
  return new JComboBox<Icon>(model) {
    @Override public Dimension getPreferredSize() {
      Insets i = getInsets();
      int w = proto.getIconWidth();
      int h = proto.getIconHeight();
      int totalCount = getItemCount();
      int columnCount = totalCount / rowCount + (totalCount % rowCount == 0 ? 0 : 1);
      return new Dimension(w * columnCount + i.left + i.right, h + i.top + i.bottom);
    }

    @Override public void updateUI() {
      super.updateUI();
      setMaximumRowCount(rowCount);
      setPrototypeDisplayValue(proto);

      Accessible o = getAccessibleContext().getAccessibleChild(0);
      if (o instanceof ComboPopup) {
        JList<?> list = ((ComboPopup) o).getList();
        list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
        list.setVisibleRowCount(rowCount);
        list.setFixedCellWidth(proto.getIconWidth());
        list.setFixedCellHeight(proto.getIconHeight());
      }
    }
  };
}
 
Example 27
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
protected Optional<JList<?>> getList() {
  Accessible a = getAccessibleContext().getAccessibleChild(0);
  if (a instanceof ComboPopup) {
    return Optional.of(((ComboPopup) a).getList());
  }
  return Optional.empty();
}
 
Example 28
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override protected void updateItem(int index) {
  if (isPopupVisible()) {
    CheckableItem item = getItemAt(index);
    item.setSelected(!item.isSelected());
    repaint();
    Accessible a = getAccessibleContext().getAccessibleChild(0);
    if (a instanceof ComboPopup) {
      ((ComboPopup) a).getList().repaint();
    }
  }
}
 
Example 29
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override protected ComboPopup createPopup() {
  return new BasicComboPopup(comboBox) {
    @Override public void show() {
      System.out.println("togglePopup");
      // super.show();
    }
  };
}
 
Example 30
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
protected static void repaintComboBox(JComboBox<?> combo, int row) {
  if (combo.getSelectedIndex() == row) {
    combo.repaint();
  }
  Accessible a = combo.getAccessibleContext().getAccessibleChild(0);
  if (a instanceof ComboPopup) {
    JList<?> list = ((ComboPopup) a).getList();
    if (list.isShowing()) {
      list.repaint(list.getCellBounds(row, row));
    }
  }
}