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:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = new String[50];
    for (int i = 0; i < items.length; i++) {
        items[i] = "" + Math.random();
    }/*from w w w .  j a v  a  2  s  . c om*/
    JComboBox cb = new JComboBox(items);

    // Retrieve the current max visible rows
    int maxVisibleRows = cb.getMaximumRowCount();

    // Change the current max visible rows
    maxVisibleRows = 20;
    cb.setMaximumRowCount(maxVisibleRows);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame window = new JFrame("Example");

    JPanel contentPane = new JPanel();

    contentPane.setLayout(new GridBagLayout());

    JComboBox comboBoxfields = new JComboBox(COMBO_BOX_ELEMENTS);

    comboBoxfields.setFont(new Font("sansserif", Font.TRUETYPE_FONT | Font.PLAIN, 15));
    comboBoxfields.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));

    comboBoxfields.setMaximumRowCount(5);

    comboBoxfields.addActionListener(/*from ww  w .  j  a  v a 2 s  .  c o m*/
            e -> System.out.println("'" + comboBoxfields.getSelectedItem().toString() + "'" + " was selected"));

    contentPane.add(comboBoxfields);

    window.add(contentPane);
    window.setSize(500, 500);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setVisible(true);
}

From source file:Main.java

public static void setFont(JComponent component, Font font, ComponentOrientation componentOrientation) {
    component.setFont(font);//from   ww w . jav  a2 s .  com

    if (component instanceof JTextField) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JTextArea) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JTextPane) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JScrollPane) {
        for (Component cmp : component.getComponents()) {
            setFont((JComponent) cmp, font, componentOrientation);
        }
    }

    if (component instanceof JTree) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JComboBox) {
        component.setComponentOrientation(componentOrientation);
        JComboBox comboBox = (JComboBox) component;
        ((BasicComboBoxRenderer) comboBox.getRenderer()).setHorizontalAlignment(SwingConstants.RIGHT);
        ((BasicComboBoxRenderer) comboBox.getRenderer()).setAutoscrolls(true);
        comboBox.setMaximumRowCount(20);
    }

    /* if(component instanceof JLabel) {
     ((JLabel)component).setHorizontalTextPosition(SwingConstants.RIGHT);
     }*/

    if (component instanceof JPanel) {
        JPanel panel = (JPanel) component;
        if (panel.getBorder() != null && panel.getBorder() instanceof TitledBorder) {
            ((TitledBorder) panel.getBorder()).setTitleFont(font);
            panel.setComponentOrientation(componentOrientation);
        }
        for (Component cmp : component.getComponents()) {
            setFont((JComponent) cmp, font, componentOrientation);
        }
    }

    if (component instanceof JTabbedPane) {
        JTabbedPane tabbedPane = (JTabbedPane) component;
        int tabCount = tabbedPane.getTabCount();
        for (int i = 0; i < tabCount; i++) {
            setFont((JComponent) tabbedPane.getComponentAt(i), font, componentOrientation);
        }
    }
}

From source file:ComboBoxWithItemChangedListener.java

public ComboPanel() {
    final JComboBox combo = new JComboBox(treasure);
    combo.setMaximumRowCount(5);
    combo.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            System.out.println("Combo: " + combo.getSelectedItem());
        }/*  w w w . j av  a2  s  .  co m*/
    });
    combo.setSelectedIndex(4);
    add(combo);
}

From source file:JComboBoxDemo.java

public JComboBoxDemo() {
    JComboBox itemsComboBox = new JComboBox(new String[] { "A", "L", "M" });
    itemsComboBox.setEditable(true);/*from  w  ww  .j a v  a  2s . co  m*/
    itemsComboBox.setMaximumRowCount(3);
    this.getContentPane().add(itemsComboBox);
    itemsComboBox.setVisible(true);
    applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT);
    this.validate();
    this.repaint();
}

From source file:Main.java

public Main() {
    JComboBox itemsComboBox = new JComboBox(new String[] { "A", "L", "M" });
    itemsComboBox.setEditable(true);//from w w w.jav  a  2s.c o m
    itemsComboBox.setMaximumRowCount(3);
    this.getContentPane().add(itemsComboBox);
    itemsComboBox.setVisible(true);
    applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT);
    this.validate();
    this.repaint();
}

From source file:Main.java

public Main() {
    JComboBox comboBox = new JComboBox();
    comboBox.addItem(new Item(1, "-"));
    comboBox.addItem(new Item(2, "X"));
    comboBox.addItem(new Item(3, "Y"));
    comboBox.setMaximumRowCount(3);
    comboBox.setPrototypeDisplayValue(" None of the above ");
    comboBox.addActionListener(e -> {
        JComboBox c = (JComboBox) e.getSource();
        Item item = (Item) c.getSelectedItem();
        System.out.println(item.getId() + " : " + item.getDescription());
    });/*www  . j a v a2s .  c  o m*/
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(comboBox);
    frame.pack();
    frame.setVisible(true);
}

From source file:MainClass.java

public MainClass() {
    // Build a mapping from book titles to their entries
    for (int i = 0; i < items.length; i++) {
        itemMap.put(items[i].getTitle(), items[i]);
    }/*w ww . j  av  a2s  . c  om*/

    setLayout(new BorderLayout());

    JComboBox bookCombo = new JComboBox(items);
    bookCombo.setEditable(true);
    bookCombo.setEditor(new MyComboBoxEditor(itemMap, items[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:Main.java

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

    setLayout(new BorderLayout());

    JComboBox bookCombo = new JComboBox(items);
    bookCombo.setEditable(true);
    bookCombo.setEditor(new MyComboBoxEditor(itemMap, items[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:net.brtly.monkeyboard.plugin.ConsolePanel.java

public ConsolePanel(PluginDelegate service) {
    super(service);
    setLayout(new MigLayout("inset 5", "[grow][:100:100][24:n:24][24:n:24]", "[::24][grow]"));

    JComboBox comboBox = new JComboBox();
    comboBox.setToolTipText("Log Level");
    comboBox.setMaximumRowCount(6);
    comboBox.setModel(/*from w  w w .j a v a2 s .c o m*/
            new DefaultComboBoxModel(new String[] { "Fatal", "Error", "Warn", "Info", "Debug", "Trace" }));
    comboBox.setSelectedIndex(5);
    add(comboBox, "cell 1 0,growx");

    JButton btnC = new JButton("");
    btnC.setToolTipText("Clear Buffer");
    btnC.setIcon(new ImageIcon(ConsolePanel.class.getResource("/img/clear-document.png")));
    btnC.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent arg0) {
            logPangrams();
        }
    });
    add(btnC, "cell 2 0,wmax 24,hmax 26");

    tglbtnV = new JToggleButton("");
    tglbtnV.setToolTipText("Auto Scroll");
    tglbtnV.setIcon(new ImageIcon(ConsolePanel.class.getResource("/img/auto-scroll.png")));
    tglbtnV.setSelected(true);
    tglbtnV.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
                _table.setAutoScroll(true);
            } else if (ev.getStateChange() == ItemEvent.DESELECTED) {
                _table.setAutoScroll(false);
            }
        }
    });

    add(tglbtnV, "cell 3 0,wmax 24,hmax 26");

    scrollPane = new JScrollPane();
    scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            // TODO figure out what to do with this event?
        }
    });

    add(scrollPane, "cell 0 1 4 1,grow");

    _table = new JLogTable("Time", "Source", "Message");

    _table.getColumnModel().getColumn(0).setMinWidth(50);
    _table.getColumnModel().getColumn(0).setPreferredWidth(50);
    _table.getColumnModel().getColumn(0).setMaxWidth(100);

    _table.getColumnModel().getColumn(1).setMinWidth(50);
    _table.getColumnModel().getColumn(1).setPreferredWidth(50);
    _table.getColumnModel().getColumn(1).setMaxWidth(100);

    _table.getColumnModel().getColumn(2).setMinWidth(50);
    _table.getColumnModel().getColumn(2).setWidth(255);

    _table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

    scrollPane.setViewportView(_table);

    _appender = new JLogTableAppender();
    _appender.setThreshold(Level.ALL);
    Logger.getRootLogger().addAppender(_appender);
}