Java Code Examples for javax.swing.plaf.basic.BasicComboPopup#getList()

The following examples show how to use javax.swing.plaf.basic.BasicComboPopup#getList() . 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 File: BoundsPopupMenuListener.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Adjusts the width of the scrollpane used by the popup.
 */
protected void popupWider(BasicComboPopup popup) {
  JList<?> list = popup.getList();

  //  Determine the maximimum width to use:
  //  a) determine the popup preferred width
  //  b) ensure width is not less than the scroll pane width
  int popupWidth = list.getPreferredSize().width
      + 5 // make sure horizontal scrollbar doesn't appear
      + getScrollBarWidth(popup, scrollPane);

  Dimension scrollPaneSize = scrollPane.getPreferredSize();
  popupWidth = Math.max(popupWidth, scrollPaneSize.width);

  //  Adjust the width
  scrollPaneSize.width = popupWidth;
  scrollPane.setPreferredSize(scrollPaneSize);
  scrollPane.setMaximumSize(scrollPaneSize);
}
 
Example 2
Source File: BoundsPopupMenuListener.java    From Juicebox with MIT License 6 votes vote down vote up
private void popupWider(BasicComboPopup popup) {
    @SuppressWarnings("unchecked")
    JList<E> list = (JList<E>) popup.getList();

    //  Determine the maximimum width to use:
    //  a) determine the popup preferred width
    //  b) limit width to the maximum if specified
    //  c) ensure width is not less than the scroll pane width

    int popupWidth = list.getPreferredSize().width
            + 5  // make sure horizontal scrollbar doesn't appear
            + getScrollBarWidth(popup, scrollPane);

    if (maximumWidth != -1) {
        popupWidth = Math.min(popupWidth, maximumWidth);
    }

    Dimension scrollPaneSize = scrollPane.getPreferredSize();
    popupWidth = Math.max(popupWidth, scrollPaneSize.width);

    //  Adjust the width

    scrollPaneSize.width = popupWidth;
    scrollPane.setPreferredSize(scrollPaneSize);
    scrollPane.setMaximumSize(scrollPaneSize);
}
 
Example 3
Source File: BoundsPopupMenuListener.java    From openAGV with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the scroll pane used by the popup so its bounds can be adjusted.
 */
protected JScrollPane getScrollPane(BasicComboPopup popup) {
  JList<?> list = popup.getList();
  Container c = SwingUtilities.getAncestorOfClass(JScrollPane.class, list);

  return (JScrollPane) c;
}
 
Example 4
Source File: BoundsPopupMenuListener.java    From Juicebox with MIT License 5 votes vote down vote up
private JScrollPane getScrollPane(BasicComboPopup popup) {
    @SuppressWarnings("unchecked")
    JList<E> list = (JList<E>) popup.getList();
    Container c = SwingUtilities.getAncestorOfClass(JScrollPane.class, list);

    return (JScrollPane) c;
}
 
Example 5
Source File: BoundsPopupMenuListener.java    From Juicebox with MIT License 5 votes vote down vote up
private boolean horizontalScrollBarWillBeVisible(BasicComboPopup popup, JScrollPane scrollPane) {
    @SuppressWarnings("unchecked")
    JList<E> list = (JList<E>) popup.getList();
    int scrollBarWidth = getScrollBarWidth(popup, scrollPane);
    int popupWidth = list.getPreferredSize().width + scrollBarWidth;

    return popupWidth > scrollPane.getPreferredSize().width;
}
 
Example 6
Source File: AbstractSuggestionBoxValueCellEditor.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private void makeComboBoxDropDownWider() {
	Object child = comboBox.getAccessibleContext().getAccessibleChild(0);
	BasicComboPopup popup = (BasicComboPopup) child;
	Insets borderInsets = popup.getBorder().getBorderInsets(popup);
	JList<?> list = popup.getList();
	Dimension preferred = list.getPreferredSize();

	IntUnaryOperator extractWidth = i -> comboBox.getRenderer()
			.getListCellRendererComponent(list, model.getElementAt(i), i, false, false)
			.getPreferredSize().width + 3;
	preferred.width = IntStream.range(0, model.getSize()).map(extractWidth)
			.reduce(comboBox.getWidth() - borderInsets.left - borderInsets.right, Integer::max);

	int itemCount = comboBox.getItemCount();
	int rowHeight = 10;
	if (itemCount > 0) {
		rowHeight = preferred.height / itemCount;
	}
	int maxHeight = comboBox.getMaximumRowCount() * rowHeight;
	preferred.height = Math.min(preferred.height, maxHeight);

	Container c = SwingUtilities.getAncestorOfClass(JScrollPane.class, list);
	JScrollPane scrollPane = (JScrollPane) c;

	scrollPane.setPreferredSize(preferred);
	scrollPane.setMaximumSize(preferred);

	if (popup.isShowing()) { // 
		// a little trick to fire Popup.showPopup method that takes care of correct display
		popup.setLocation(comboBox.getLocationOnScreen().x, popup.getLocationOnScreen().y - 1);
	}

	Dimension popupSize = new Dimension();
	popupSize.width = preferred.width + borderInsets.left + borderInsets.right;
	popupSize.height = preferred.height + borderInsets.top + borderInsets.bottom;
	Component parent = popup.getParent();
	if (parent != null) {
		parent.setSize(popupSize);
		parent.validate();
		parent.repaint();
	}
}
 
Example 7
Source File: SwingUtils.java    From WorldGrower with GNU General Public License v3.0 4 votes vote down vote up
public static void setComboBoxSelectionColor(JComboBox comboBox, Color color) {
	Object child = comboBox.getAccessibleContext().getAccessibleChild(0);
	BasicComboPopup popup = (BasicComboPopup)child;
	JList list = popup.getList();
	list.setSelectionForeground(color);
}