Example usage for javax.swing JComboBox setMaximumRowCount

List of usage examples for javax.swing JComboBox setMaximumRowCount

Introduction

In this page you can find the example usage for javax.swing JComboBox setMaximumRowCount.

Prototype

@BeanProperty(preferred = true, description = "The maximum number of rows the popup should have")
public void setMaximumRowCount(int count) 

Source Link

Document

Sets the maximum number of rows the JComboBox displays.

Usage

From source file:EditableComboBox.java

public EditableComboBox() {
    // Build a mapping from book titles to their entries
    for (int i = 0; i < books.length; i++) {
        bookMap.put(books[i].getTitle(), books[i]);
    }// w ww .ja  va 2  s  .  c o m

    setLayout(new BorderLayout());

    JComboBox bookCombo = new JComboBox(books);
    bookCombo.setEditable(true);
    bookCombo.setEditor(new ComboBoxEditorExample(bookMap, books[0]));
    bookCombo.setMaximumRowCount(4);
    bookCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("You chose " + ((JComboBox) e.getSource()).getSelectedItem() + "!");
        }
    });
    bookCombo.setActionCommand("Hello");
    add(bookCombo, BorderLayout.CENTER);
}

From source file:CustomComboBoxDemo.java

public CustomComboBoxDemo() {
    super(new BorderLayout());

    //Load the pet images and create an array of indexes.
    images = new ImageIcon[petStrings.length];
    Integer[] intArray = new Integer[petStrings.length];
    for (int i = 0; i < petStrings.length; i++) {
        intArray[i] = new Integer(i);
        images[i] = createImageIcon("images/" + petStrings[i] + ".gif");
        if (images[i] != null) {
            images[i].setDescription(petStrings[i]);
        }/*from  ww w. ja  va  2  s  .  co  m*/
    }

    //Create the combo box.
    JComboBox petList = new JComboBox(intArray);
    ComboBoxRenderer renderer = new ComboBoxRenderer();
    renderer.setPreferredSize(new Dimension(200, 130));
    petList.setRenderer(renderer);
    petList.setMaximumRowCount(3);

    //Lay out the demo.
    add(petList, BorderLayout.PAGE_START);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:mod.steps.stepmode.threads.forms.TransitionsChooser.java

private JComboBox initializeNewComboBox(String transitionId) {
    Map<String, Integer> repetitions = listChoosenElement.getPossibleRepetitions();
    JComboBox rComboBox = new JComboBox();
    int count = repetitions.get(transitionId);
    rComboBox.setMaximumRowCount(count);
    for (int i = 1; i <= count; i++) {
        rComboBox.addItem(i + "");
    }//from   www  . j  a v  a2 s  .co m

    return rComboBox;
}

From source file:burp.BurpExtender.java

private <T> JComboBox<T> createComboBox(String label, Container cont, int buttonY, JButton button) {
    createSettingsLabel(label, cont);//  ww  w.  ja  v a 2  s  .  com

    JComboBox<T> box = new JComboBox<T>();
    box.setMaximumRowCount(16);
    callbacks.customizeUiComponent(box);
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    cont.add(box, gbc);

    button.setIcon(refreshSpinner[0]);
    button.setPreferredSize(
            new Dimension(refreshSpinner[0].getIconHeight() + 4, refreshSpinner[0].getIconHeight() + 4));
    callbacks.customizeUiComponent(button);
    gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = buttonY;
    gbc.anchor = GridBagConstraints.WEST;
    cont.add(button, gbc);

    return box;
}

From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java

/**
 * Helper factory method for creating a language selector that provides functionality to change the locale.
 *
 * @param width/*w  ww.j  a  v  a 2  s .c  o  m*/
 *         the preferred width of the component in pixels
 * @return the newly created language selector
 */
protected JComboBox createLanguageSelector(int width) {
    Preconditions.checkArgument(width >= 0);
    final JComboBox<SupportedLocale> selector = new JComboBox(i18n.getSupportedLocales().toArray());
    selector.setSelectedItem(i18n.getCurrentSupportedLocale());
    selector.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            i18n.setLocale((SupportedLocale) selector.getSelectedItem());
        }
    });
    int height = selector.getPreferredSize().height;
    selector.setMinimumSize(new Dimension(width, height));
    selector.setMaximumSize(new Dimension(width, height));
    selector.setPreferredSize(new Dimension(width, height));
    selector.setMaximumRowCount(i18n.getSupportedLocales().size());
    selector.setComponentOrientation(ComponentOrientation.getOrientation(i18n.getLocale()));
    return selector;
}

From source file:com.t3.macro.api.functions.input.ColumnPanel.java

/** Creates a dropdown list control. */
public JComponent createListControl(VarSpec vs) {
    JComboBox combo;
    boolean showText = vs.optionValues.optionEquals("TEXT", "TRUE");
    boolean showIcons = vs.optionValues.optionEquals("ICON", "TRUE");
    int iconSize = vs.optionValues.getNumeric("ICONSIZE", 0);
    if (iconSize <= 0)
        showIcons = false;/*from  w ww  .  jav a 2s .  c om*/

    // Build the combo box
    for (int j = 0; j < vs.valueList.size(); j++) {
        if (StringUtils.isEmpty(vs.valueList.get(j))) {
            // Using a non-empty string prevents the list entry from having zero height.
            vs.valueList.set(j, " ");
        }
    }
    if (!showIcons) {
        // Swing has an UNBELIEVABLY STUPID BUG when multiple items in a JComboBox compare as equal.
        // The combo box then stops supporting navigation with arrow keys, and
        // no matter which of the identical items is chosen, it returns the index
        // of the first one.  Sun closed this bug as "by design" in 1998.
        // A workaround found on the web is to use this alternate string class (defined below)
        // which never reports two items as being equal.
        NoEqualString[] nesValues = new NoEqualString[vs.valueList.size()];
        for (int i = 0; i < nesValues.length; i++)
            nesValues[i] = new NoEqualString(vs.valueList.get(i));
        combo = new JComboBox(nesValues);
    } else {
        combo = new JComboBox();
        combo.setRenderer(new ComboBoxRenderer());
        Pattern pattern = ASSET_PATTERN;

        for (String value : vs.valueList) {
            Matcher matcher = pattern.matcher(value);
            String valueText, assetID;
            Icon icon = null;

            // See if the value string for this item has an image URL inside it
            if (matcher.find()) {
                valueText = matcher.group(1);
                assetID = matcher.group(2);
            } else {
                valueText = value;
                assetID = null;
            }

            // Assemble a JLabel and put it in the list
            UpdatingLabel label = new UpdatingLabel();
            icon = InputFunctions.getIcon(assetID, iconSize, label);
            label.setOpaque(true); // needed to make selection highlighting show up
            if (showText)
                label.setText(valueText);
            if (icon != null)
                label.setIcon(icon);
            combo.addItem(label);
        }
    }
    int listIndex = vs.optionValues.getNumeric("SELECT");
    if (listIndex < 0 || listIndex >= vs.valueList.size())
        listIndex = 0;
    combo.setSelectedIndex(listIndex);
    combo.setMaximumRowCount(20);
    return combo;
}

From source file:org.smart.migrate.ui.MappingDialog.java

private void initFieldMappings() {
    if (StringUtils.isBlank((String) cbxSourceTables.getSelectedItem())
            || StringUtils.isBlank((String) cbxTargetTables.getSelectedItem())) {
        return;//from  w w  w.  j  a  v a  2  s.  c om
    }
    DefaultTableModel model = (DefaultTableModel) tblFieldMapping.getModel();
    model.setRowCount(0);
    TableColumn srcColumn = tblFieldMapping.getColumnModel().getColumn(0);
    TableColumn tgtColumn = tblFieldMapping.getColumnModel().getColumn(1);
    JComboBox srcComboBox = new JComboBox();
    srcComboBox.setMaximumRowCount(20);

    List<Field> srcFields = sourceMetaDao.getFieldsOfTable(sourceConnection,
            cbxSourceTables.getSelectedItem().toString());
    List<Field> tgtFields = targetMetaDao.getFieldsOfTable(targetConnection,
            cbxTargetTables.getSelectedItem().toString());

    srcComboBox.addItem("");
    for (Field field : srcFields) {
        srcComboBox.addItem(field.getName());
    }

    srcColumn.setCellEditor(new DefaultCellEditor(srcComboBox));

    int k = 0;
    for (Field tgtField : tgtFields) {
        k++;
        model.addRow(new Object[] { null, tgtField.getName(), false, null, null, k });
    }

    if (tableSetting != null && !CollectionUtils.isEmpty(tableSetting.getFieldSettings())
            && tableSetting.getSourceTable().equals(cbxSourceTables.getSelectedItem())
            && tableSetting.getTargetTable().equals(cbxTargetTables.getSelectedItem())) {

        for (int i = 0; i < tblFieldMapping.getRowCount(); i++) {
            String tgtField = (String) tblFieldMapping.getValueAt(i, 1);
            FieldSetting fieldSetting = tableSetting.getFieldSettingByTargetField(tgtField);
            if (fieldSetting != null) {
                tblFieldMapping.setValueAt(fieldSetting.getSourceField(), i, 0);
                tblFieldMapping.setValueAt(fieldSetting.isPrimaryKey(), i, 2);
                tblFieldMapping.setValueAt(fieldSetting.getDefaultValue(), i, 3);
                tblFieldMapping.setValueAt(fieldSetting.getDictText(), i, 4);
            }
        }
    }
}

From source file:ro.nextreports.designer.chart.ChartPropertyPanel.java

private Property getTypeProperty() {
    DefaultProperty typeProp = new DefaultProperty();
    typeProp.setName(CHART_TYPE);// w  ww . java  2  s.c  o m
    typeProp.setDisplayName(TYPE_PARAM_NAME);
    typeProp.setType(String.class);
    ComboBoxPropertyEditor typeEditor = new ComboBoxPropertyEditor();
    typeEditor.setAvailableValues(new String[] { BAR, BAR_COMBO, HORIZONTAL_BAR, STACKED_BAR, STACKED_BAR_COMBO,
            HORIZONTAL_STACKED_BAR, PIE, LINE, AREA, BUBBLE });
    typeEditor.setAvailableIcons(new Icon[] { ImageUtil.getImageIcon("chart_bar"),
            ImageUtil.getImageIcon("chart_bar_combo"), ImageUtil.getImageIcon("chart_horizontal_bar"),
            ImageUtil.getImageIcon("chart_stacked_bar"), ImageUtil.getImageIcon("chart_stacked_bar_combo"),
            ImageUtil.getImageIcon("chart_horizontal_stacked_bar"), ImageUtil.getImageIcon("chart_pie"),
            ImageUtil.getImageIcon("chart_line"), ImageUtil.getImageIcon("chart_area"),
            ImageUtil.getImageIcon("chart_bubble") });
    JComboBox cb = (JComboBox) typeEditor.getCustomEditor();
    cb.setMaximumRowCount(10);
    ChartType chartType = chart.getType();
    byte type = ChartType.NONE;
    if (chartType != null) {
        type = chartType.getType();
    }
    setChartType(type, typeProp);
    typeProp.setCategory(I18NSupport.getString("property.category.main"));

    editorRegistry.registerEditor(typeProp, typeEditor);

    return typeProp;
}