Example usage for javax.swing JComboBox setModel

List of usage examples for javax.swing JComboBox setModel

Introduction

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

Prototype

@BeanProperty(description = "Model that the combo box uses to get data to display.")
public void setModel(ComboBoxModel<E> aModel) 

Source Link

Document

Sets the data model that the JComboBox uses to obtain the list of items.

Usage

From source file:EHRAppointment.ChartPanelDraw.java

private JComboBox createDate() { // to change the vertical and horizontal data
    final JComboBox date = new JComboBox();
    final String[] dateCmds = { "Horizontal Dates", "Vertical Dates" };
    date.setModel(new DefaultComboBoxModel(dateCmds));
    date.addActionListener(new ActionListener() {

        @Override//from   w w w. j av  a  2s.  co m
        public void actionPerformed(ActionEvent e) {
            JFreeChart chart = chartPanel.getChart();
            XYPlot plot = (XYPlot) chart.getPlot();
            DateAxis domain = (DateAxis) plot.getDomainAxis();
            if (dateCmds[0].equals(date.getSelectedItem())) {
                domain.setVerticalTickLabels(false);
            } else {
                domain.setVerticalTickLabels(true);
            }
        }
    });
    return date;
}

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);/*  w  w w.j a  v a2  s  .c o m*/
    comboBox.setModel(
            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);
}

From source file:edu.gmu.cs.sim.util.media.chart.BarChartGenerator.java

protected void buildGlobalAttributes(LabelledList list) {
    // create the chart
    CategoryPlot plot = (CategoryPlot) (chart.getPlot());
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinePaint(new Color(200, 200, 200));
    plot.setRangeGridlinePaint(new Color(200, 200, 200));

    // define the renderers
    barRenderer = new BarRenderer();
    reviseRenderer(barRenderer);//from ww w  . j  av  a2s  .  co  m

    stackedBarRenderer = new StackedBarRenderer(false);
    reviseRenderer(stackedBarRenderer);

    percentageRenderer = new StackedBarRenderer(true);
    reviseRenderer(percentageRenderer);

    plot.setRenderer(barRenderer);

    xLabel = new PropertyField() {
        public String newValue(String newValue) {
            setXAxisLabel(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    xLabel.setValue(getXAxisLabel());

    list.add(new JLabel("X Label"), xLabel);

    yLabel = new PropertyField() {
        public String newValue(String newValue) {
            setYAxisLabel(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    yLabel.setValue(getYAxisLabel());

    list.add(new JLabel("Y Label"), yLabel);

    final JCheckBox gridlines = new JCheckBox();
    gridlines.setSelected(false);
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            hasgridlines = (e.getStateChange() == ItemEvent.SELECTED);
            updateGridLines();
        }
    };
    gridlines.addItemListener(il);

    list.add(new JLabel("Grid Lines"), gridlines);

    final JCheckBox labels = new JCheckBox();
    labels.setSelected(true);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                getBarRenderer().setBaseItemLabelsVisible(true);
                getStackedBarRenderer().setBaseItemLabelsVisible(true);
                getPercentageRenderer().setBaseItemLabelsVisible(true);
            } else {
                getBarRenderer().setBaseItemLabelsVisible(false);
                getStackedBarRenderer().setBaseItemLabelsVisible(false);
                getPercentageRenderer().setBaseItemLabelsVisible(false);
            }
        }
    };
    labels.addItemListener(il);
    list.add(new JLabel("Labels"), labels);

    final JComboBox barType = new JComboBox();
    barType.setEditable(false);
    barType.setModel(new DefaultComboBoxModel(
            new java.util.Vector(Arrays.asList(new String[] { "Separate", "Stacked", "Percentage" }))));
    barType.setSelectedIndex(0);
    barType.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            CategoryPlot plot = (CategoryPlot) (chart.getPlot());
            int type = barType.getSelectedIndex();

            if (type == 0) // separate
            {
                plot.setRenderer(getBarRenderer());
            } else if (type == 1) // stacked
            {
                plot.setRenderer(getStackedBarRenderer());
            } else // percentage
            {
                plot.setRenderer(getPercentageRenderer());
            }
        }
    });
    list.add(new JLabel("Bars"), barType);

    final JCheckBox horizontal = new JCheckBox();
    horizontal.setSelected(false);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            CategoryPlot plot = (CategoryPlot) (chart.getPlot());
            if (e.getStateChange() == ItemEvent.SELECTED) {
                plot.setOrientation(PlotOrientation.HORIZONTAL);
                ishorizontal = true;
            } else {
                plot.setOrientation(PlotOrientation.VERTICAL);
                ishorizontal = false;
            }
            updateGridLines();
        }
    };
    horizontal.addItemListener(il);

    list.add(new JLabel("Horizontal"), horizontal);
}

From source file:com.github.alexfalappa.nbspringboot.projects.initializr.InitializrProjectPanelVisual1.java

private void fillCombo(JsonNode attrNode, DefaultComboBoxModel<NamedItem> comboModel, JComboBox combo) {
    JsonNode valArray = attrNode.path("values");
    comboModel.removeAllElements();/* w  ww.  ja v a  2 s .c om*/
    for (JsonNode val : valArray) {
        comboModel.addElement(new NamedItem(val.get("id").asText(), val.get("name").asText()));
    }
    combo.setModel(comboModel);
    combo.setSelectedItem(new NamedItem(attrNode.path("default").asText(), ""));
}

From source file:com.emr.schemas.TableRelationsForm.java

/**
 * Constructor/*from w  w  w  . j a v a  2 s. c  o  m*/
 * @param tables {@link List} List of source tables
 */
public TableRelationsForm(List tables, SchemerMapper parent) {
    fileManager = null;
    dbManager = null;
    emrConn = null;
    this.parent = parent;
    this.tables = tables; //source tables

    //Create KenyaEMR DB connection
    fileManager = new FileManager();
    String[] settings = fileManager.getConnectionSettings("emr_database.properties", "emr");
    if (settings == null) {
        //Connection settings not found
        JOptionPane.showMessageDialog(null,
                "Database Settings not found. Please set the connection settings for the database first.",
                "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE);
        //Open KenyaEMRConnectionForm form
    } else {
        if (settings.length < 1) {
            JOptionPane.showMessageDialog(null,
                    "Database Settings not found. Please set the connection settings for the database first.",
                    "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE);
            //Open KenyaEMRConnectionForm form
        } else {
            //Connection settings are ok
            //We establish a connection
            dbManager = new DatabaseManager(settings[0], settings[1], settings[3], settings[4], settings[5]);
            emrConn = dbManager.getConnection();
            if (emrConn == null) {
                JOptionPane.showMessageDialog(null, "Test Connection Failed", "Connection Test",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    //get all columns and add them to the columns list
    for (Object table : tables) {
        String tablename = (String) table;
        populateTableColumnsToList(tablename);
    }

    model = new DefaultTableModel(
            new Object[] { "Primary Table", "Column", "Reference Table", "Foreign Column" }, 10);

    initComponents();
    this.setClosable(true);
    foreignTables = tables;
    combo1 = new JComboBox();//Combobox for the primary tables
    combo2 = new JComboBox();
    combo3 = new JComboBox();
    combo4 = new JComboBox();
    combo1.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) event.getItem();
                //populate primary table columns
                primaryColumns = getTableColumns(selectedTable);
                DefaultComboBoxModel combo2_model = new DefaultComboBoxModel(
                        primaryColumns.toArray(new String[primaryColumns.size()]));
                JComboBox comboBox = new JComboBox();
                comboBox.setModel(combo2_model);
                relationsTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox));

            }
        }
    });

    combo3.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) event.getItem();
                //populate foreign table columns
                foreignColumns = getTableColumns(selectedTable);
                DefaultComboBoxModel combo3_model = new DefaultComboBoxModel(
                        foreignColumns.toArray(new String[foreignColumns.size()]));
                JComboBox comboBox = new JComboBox();
                comboBox.setModel(combo3_model);
                relationsTable.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(comboBox));
            }
        }
    });
    ComboBoxTableCellEditor primaryTableEditor = new ComboBoxTableCellEditor(tables, combo1);
    ComboBoxTableCellEditor primaryTableColumns = new ComboBoxTableCellEditor(primaryColumns, combo2);

    ComboBoxTableCellEditor foreignTableEditor = new ComboBoxTableCellEditor(foreignTables, combo3);//TODO: remove selected primary table from list

    ComboBoxTableCellEditor foreignTableColumns = new ComboBoxTableCellEditor(foreignColumns, combo4);
    relationsTable.getColumnModel().getColumn(0).setCellEditor(primaryTableEditor);
    relationsTable.getColumnModel().getColumn(1).setCellEditor(primaryTableColumns);
    relationsTable.getColumnModel().getColumn(2).setCellEditor(foreignTableEditor);
    relationsTable.getColumnModel().getColumn(3).setCellEditor(foreignTableColumns);

    columnsList.setCellRenderer(new CheckboxListCellRenderer());
    SourceTablesListener listSelectionListener = new SourceTablesListener(new JTextArea(), selected_columns);
    columnsList.addListSelectionListener(listSelectionListener);
    columnsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    columnsList.setSelectionModel(new DefaultListSelectionModel() {
        @Override
        public void setSelectionInterval(int index0, int index1) {
            if (isSelectedIndex(index0))
                super.removeSelectionInterval(index0, index1);
            else
                super.addSelectionInterval(index0, index1);
        }
    });
}

From source file:au.org.ala.delta.intkey.ui.WebSearchDialog.java

private void loadSearchEngines(File file, JComboBox cmb) {

    List<SearchEngineDescriptor> engines = new ArrayList<WebSearchDialog.SearchEngineDescriptor>();
    try {/*from  w  w w .j a v  a  2s .  c  o  m*/
        List<String> lines = FileUtils.readLines(file);
        for (String line : lines) {
            SearchEngineDescriptor desc = parseSearchEngineDescriptor(line);
            if (desc != null) {
                engines.add(desc);
            } else {
                Logger.log("Could not parse search engine descriptor: " + line);
            }
        }

        ComboBoxModel model = new DefaultComboBoxModel(engines.toArray());
        cmb.setModel(model);
        if (model.getSize() > 0) {
            model.setSelectedItem(model.getElementAt(0));
        }

    } catch (IOException ioex) {
        throw new RuntimeException(ioex);
    }
}

From source file:edu.harvard.mcz.imagecapture.VerbatimClassifyDialog.java

/**
 * This method initializes jTableNumbers   
 *    //w  w w  .  j  a va  2  s. c  o  m
 * @return javax.swing.JTable   
 */
private JTable getJTableNumbers() {
    if (jTableNumbers == null) {
        jTableNumbers = new JTable(new NumberTableModel());
        JComboBox<String> jComboNumberTypes = new JComboBox<String>();
        jComboNumberTypes.setModel(new DefaultComboBoxModel<String>(NumberLifeCycle.getDistinctTypes()));
        jComboNumberTypes.setEditable(true);
        TableColumn typeColumn = jTableNumbers.getColumnModel().getColumn(NumberTableModel.COLUMN_TYPE);
        DefaultCellEditor comboBoxEditor = new DefaultCellEditor(jComboNumberTypes);
        //TODO: enable autocomplete for numbertypes picklist.
        //AutoCompleteDecorator.decorate((JComboBox) comboBoxEditor.getComponent());
        typeColumn.setCellEditor(comboBoxEditor);
        DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
        renderer.setToolTipText("Click for pick list of number types.");
        typeColumn.setCellRenderer(renderer);
    }
    return jTableNumbers;
}

From source file:main.UIController.java

/************* TO GREGORIAN *************/

public void updateDayComboImladris() {
    UI window = this.getUi();

    JComboBox yen = window.getYen();
    JTextField loa = window.getLoa();
    JComboBox period = window.getPeriod();
    JComboBox day = window.getDayOfLoa();
    JButton convert = window.getToGregorian();
    JTextPane result = window.getResGregorian();
    int yenNum = yen.getSelectedIndex() + 1;
    String value = loa.getText();
    if (!value.isEmpty()) {
        try {//from ww w .  ja v  a2  s. c  o  m
            int loaNum = Integer.parseInt(value);
            if (loaNum > 0 && loaNum <= 144) {
                int periodNum = period.getSelectedIndex() + 1;
                if (periodNum == ImladrisCalendar.YESTARE || periodNum == ImladrisCalendar.METTARE) {
                    day.setEnabled(false);
                    day.setModel(new DefaultComboBoxModel());
                    convert.setEnabled(true);
                    result.setText("");
                } else {
                    int daySel = 0;
                    if (day.isEnabled()) {
                        daySel = day.getSelectedIndex() + 1;
                    }
                    ArrayList<Integer> days = ImladrisInfo.getInstance().getDaysArray(yenNum, loaNum,
                            periodNum);
                    day.setModel(new DefaultComboBoxModel(days.toArray()));
                    if (daySel > 0 && daySel <= days.size()) {
                        day.setSelectedIndex(daySel - 1);
                    }
                    day.setEnabled(true);
                    convert.setEnabled(true);
                    result.setText("");
                }
            } else {
                day.setEnabled(false);
                convert.setEnabled(false);
                day.setModel(new DefaultComboBoxModel());
                result.setText("");
            }
        } catch (NumberFormatException e) {
            day.setEnabled(false);
            convert.setEnabled(false);
            day.setModel(new DefaultComboBoxModel());
            result.setText("");
        }
    } else {
        day.setEnabled(false);
        convert.setEnabled(false);
        day.setModel(new DefaultComboBoxModel());
        result.setText("");
    }
}

From source file:main.UIController.java

/******** FROM GREGORIAN **********/

public void updateDayComboGregorian() {
    UI window = this.getUi();

    JTextField year = window.getYear();
    JComboBox month = window.getMonth();
    JComboBox day = window.getDay();
    JButton convert = window.getToImladris();
    JTextPane result = window.getResImladris();
    String value = year.getText();
    if (!value.isEmpty()) {
        try {//ww  w.  j  a  va  2 s  . co m
            int yearNum = Integer.parseInt(value);
            if (yearNum > 0 && yearNum <= GregorianInfo.MAX_SUPPORTED_YEAR) {
                int monthNum = month.getSelectedIndex() + 1;
                int daySel = 0;
                if (day.isEnabled()) {
                    daySel = day.getSelectedIndex() + 1;
                }
                ArrayList<Integer> days = GregorianInfo.getInstance().getDaysArray(yearNum, monthNum);
                day.setModel(new DefaultComboBoxModel(days.toArray()));
                if (daySel > 0 && daySel <= days.size()) {
                    day.setSelectedIndex(daySel - 1);
                }
                day.setEnabled(true);
                convert.setEnabled(true);
                result.setText("");
            } else {
                day.setEnabled(false);
                convert.setEnabled(false);
                day.setModel(new DefaultComboBoxModel());
                result.setText("");
            }
        } catch (NumberFormatException e) {
            day.setEnabled(false);
            convert.setEnabled(false);
            day.setModel(new DefaultComboBoxModel());
            result.setText("");
        }
    } else {
        day.setEnabled(false);
        convert.setEnabled(false);
        day.setModel(new DefaultComboBoxModel());
        result.setText("");
    }
}

From source file:io.github.jeddict.jpa.modeler.source.generator.ui.GenerateCodeDialog.java

private void populatePackageCombo(JComboBox packageCombo, ProjectInfo projectInfo) {
    if (projectInfo.getSourceGroup() != null) {
        packageCombo.setRenderer(PackageView.listRenderer());
        ComboBoxModel model = PackageView.createListView(projectInfo.getSourceGroup());
        if (model.getSize() > 0) {
            model.setSelectedItem(model.getElementAt(0));
        }/*from  w  w w .ja v  a  2 s.  c  o m*/
        packageCombo.setModel(model);
    }
}