Example usage for javax.swing DefaultComboBoxModel removeElementAt

List of usage examples for javax.swing DefaultComboBoxModel removeElementAt

Introduction

In this page you can find the example usage for javax.swing DefaultComboBoxModel removeElementAt.

Prototype

public void removeElementAt(int index) 

Source Link

Usage

From source file:Main.java

public static void main(final String args[]) {
    final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

    model.addElement("A");
    model.addElement("C");
    model.addElement("D");
    model.addElement("A");

    model.removeElementAt(1);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);//ww w.ja  v  a  2  s .  com
    comboBox1.setEditable(true);
    frame.add(comboBox1, BorderLayout.NORTH);

    JList<String> jlist = new JList<String>(model);
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    JButton button = new JButton("Add");
    frame.add(button, BorderLayout.SOUTH);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            model.addElement("a");
            model.insertElementAt("Z", 0);
        }
    };
    button.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:net.linra.AttendanceSystemFrame.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    JLabel[] labels = { student1, student2, student3, student4, student5, student6, student7, student8,
            student9, student10, student11, student12, student13, student14, student15, student16, student17,
            student18, student19, student20, student21, student22, student23, student24, student25 };
    if (jList1.getModel().getSize() <= 0) {
        this.jButton1.setEnabled(false);
    } else {//  w  w  w.  j a  v  a2s .c  om
        int i = studentCombobox.getSelectedIndex();
        String name = studentCombobox.getSelectedItem().toString();

        for (JLabel label : labels) {
            if (name.equals(label.getText())) {
                label.setIcon(
                        new javax.swing.ImageIcon(getClass().getResource("/net/linra/picpackage/present.png")));
            }
        }

        this.absentNumber.setText((jList1.getModel().getSize() - 1) + "");
        DefaultListModel model = (DefaultListModel) jList1.getModel();
        model.removeElementAt(i);
        DefaultComboBoxModel model2 = (DefaultComboBoxModel) studentCombobox.getModel();
        model2.removeElementAt(i);

        jPanel4.removeAll();
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(4, "", "Last Month");
        dataset.setValue(7, "", "Last Week");
        dataset.setValue(3, "", "Yesterday");
        dataset.setValue(Integer.parseInt(this.absentNumber.getText()), "", "Today");
        JFreeChart chart = ChartFactory.createBarChart("Histgram of absent student", "Data", "Absent number",
                dataset, PlotOrientation.VERTICAL, true, true, false);
        ChartPanel p = new ChartPanel(chart);
        p.setSize(jPanel4.getWidth(), jPanel4.getHeight());
        p.setVisible(true);
        jPanel4.add(p);
        jPanel4.repaint();
    }
}

From source file:edu.harvard.i2b2.query.ui.GroupPanel.java

public void setTimingComboText(String text) {
    DefaultComboBoxModel model = ((DefaultComboBoxModel) jTimingComboBox.getModel());
    //model.removeElementAt(1);
    if (text.equalsIgnoreCase("Items instance will be same")) {
        if (model.getSize() == 2) {
            model.insertElementAt(text, 2);
        }/* w w  w.ja  v  a  2 s  . c  o m*/
    } else {
        if (model.getSize() == 3) {
            model.removeElementAt(2);
        }
    }
}

From source file:paquete.HollywoodUI.java

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
    try {/*w  w w  .  ja  v a  2s.  co m*/
        Peliculas.remove(cb_delete_movie.getSelectedIndex());
        if (Peliculas.isEmpty()) {
            DefaultComboBoxModel model = (DefaultComboBoxModel) cb_delete_movie.getModel();
            model.removeAllElements();
            model.addElement("No hay mas peliculas");
        } else {
            DefaultComboBoxModel model = (DefaultComboBoxModel) cb_delete_movie.getModel();
            model.removeElementAt(Peliculas.size() - 1);
            model.addElement(Peliculas.get(Peliculas.size() - 1));
        }
        JOptionPane.showMessageDialog(delete_movie, "Pelicula eliminada por completo", "INFO",
                JOptionPane.INFORMATION_MESSAGE);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(delete_movie, "Error al tratar de eliminar la pelicula", "Error",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:pl.otros.logview.gui.actions.search.SearchAction.java

public void performSearch(String text, SearchDirection direction) {
    StatusObserver statusObserver = getOtrosApplication().getStatusObserver();
    JTabbedPane jTabbedPane = getOtrosApplication().getJTabbedPane();
    LogViewPanelWrapper lvPanel = (LogViewPanelWrapper) jTabbedPane.getSelectedComponent();
    if (lvPanel == null) {
        return;//from   ww w.ja va2s. com
    }
    JTable table = lvPanel.getLogViewPanel().getTable();

    NextRowProvider nextRowProvider = NextRowProviderFactory.getFilteredTableRow(table, direction);
    SearchContext context = new SearchContext();
    context.setDataTableModel(lvPanel.getDataTableModel());
    SearchMatcher searchMatcher = null;
    String confKey = null;
    if (SearchMode.STRING_CONTAINS.equals(searchMode)) {
        searchMatcher = new StringContainsSearchMatcher(text);
        confKey = ConfKeys.SEARCH_LAST_STRING;
    } else if (SearchMode.REGEX.equals(searchMode)) {
        try {
            searchMatcher = new RegexMatcher(text);
            confKey = ConfKeys.SEARCH_LAST_REGEX;
        } catch (Exception e) {
            statusObserver.updateStatus("Error in regular expression: " + e.getMessage(),
                    StatusObserver.LEVEL_ERROR);
            return;
        }
    } else if (SearchMode.QUERY.equals(searchMode)) {
        QueryAcceptCondition acceptCondition;
        try {
            acceptCondition = new QueryAcceptCondition(text);
            searchMatcher = new AcceptConditionSearchMatcher(acceptCondition);
            confKey = ConfKeys.SEARCH_LAST_QUERY;
        } catch (RuleException e) {
            statusObserver.updateStatus("Wrong query rule: " + e.getMessage(), StatusObserver.LEVEL_ERROR);
            return;

        }
    }
    updateList(confKey, getOtrosApplication().getConfiguration(), text);
    DefaultComboBoxModel model = (DefaultComboBoxModel) getOtrosApplication().getSearchField().getModel();
    model.removeElement(text);
    model.insertElementAt(text, 0);
    model.setSelectedItem(text);
    int maxCount = getOtrosApplication().getConfiguration().getInt(ConfKeys.SEARCH_LAST_COUNT, 30);
    while (model.getSize() > maxCount) {
        model.removeElementAt(model.getSize() - 1);
    }

    context.setSearchMatcher(searchMatcher);
    SearchResult searchNext = searchEngine.searchNext(context, nextRowProvider);
    if (searchNext.isFound()) {
        int row = table.convertRowIndexToView(searchNext.getRow());
        Rectangle rect = table.getCellRect(row, 0, true);
        table.scrollRectToVisible(rect);
        table.clearSelection();
        table.setRowSelectionInterval(row, row);
        statusObserver.updateStatus(String.format("Found at row %d", row), StatusObserver.LEVEL_NORMAL);
        if (markFound) {
            lvPanel.getDataTableModel().markRows(markerColors, table.convertRowIndexToModel(row));
        }

        scrollToSearchResult(
                searchMatcher.getFoundTextFragments(
                        lvPanel.getDataTableModel().getLogData(table.convertRowIndexToModel(row))),
                lvPanel.getLogViewPanel().getLogDetailTextArea());
    } else {
        statusObserver.updateStatus(String.format("\"%s\" not found", text), StatusObserver.LEVEL_WARNING);
    }
}