Example usage for javax.swing DefaultComboBoxModel insertElementAt

List of usage examples for javax.swing DefaultComboBoxModel insertElementAt

Introduction

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

Prototype

public void insertElementAt(E anObject, 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");

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

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);/*ww  w  . j av  a 2s  .c o  m*/
    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: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.removeElement("A");

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

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);/*from   www.j a  v  a2 s  . c om*/
    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: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);/*from  ww w  .  j av  a 2 s  . c o m*/

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

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);
    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: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.removeAllElements();//from w ww.  j  av  a  2  s. co  m

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

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);
    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: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.setSelectedItem("C");

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

    JComboBox<String> comboBox1 = new JComboBox<String>(model);
    comboBox1.setMaximumRowCount(5);/*from   w  ww .j  a  v a  2 s.  c om*/
    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:com.microsoft.intellij.forms.CreateWebSiteForm.java

private void fillResourceGroups(String valToSet) {
    try {/* w  w  w  .  j  a  v a2s .c o m*/
        if (subscription != null) {
            final List<String> groupList = AzureManagerImpl.getManager(project)
                    .getResourceGroupNames(subscription.getId());
            DefaultComboBoxModel model = new DefaultComboBoxModel(groupList.toArray());
            model.insertElementAt(createResGrpLabel, 0);
            model.setSelectedItem(null);
            groupComboBox.setModel(model);
            if (!groupList.isEmpty()) {
                if (valToSet != null && !valToSet.isEmpty()) {
                    groupComboBox.setSelectedItem(valToSet);
                } else {
                    groupComboBox.setSelectedIndex(1);
                }
                // prepare list of App Service plans for selected subscription
                if (fillPlansAcrossSub != null && !fillPlansAcrossSub.isFinished()) {
                    fillPlansAcrossSub.cancel();
                }
                IDEHelper.ProjectDescriptor projectDescriptor = new IDEHelper.ProjectDescriptor(
                        project.getName(), project.getBasePath() == null ? "" : project.getBasePath());
                fillPlansAcrossSub = DefaultLoader.getIdeHelper().runInBackground(projectDescriptor,
                        "Loading service plans...", null, new CancellableTask() {
                            @Override
                            public void onCancel() {
                            }

                            @Override
                            public void onSuccess() {
                            }

                            @Override
                            public void onError(@NotNull Throwable throwable) {
                            }

                            @Override
                            public synchronized void run(final CancellationHandle cancellationHandle)
                                    throws Throwable {
                                plansAcrossSub = new ArrayList<String>();
                                for (String groupName : groupList) {
                                    List<WebHostingPlanCache> plans = AzureManagerImpl.getManager(project)
                                            .getWebHostingPlans(subscription.getId(), groupName);
                                    for (WebHostingPlanCache plan : plans) {
                                        plansAcrossSub.add(plan.getName());
                                    }
                                }
                            }
                        });
            }
        }
    } catch (AzureCmdException e) {
        String msg = "An error occurred while loading the resource groups." + "\n"
                + String.format(message("webappExpMsg"), e.getMessage());
        PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, e);
    }
}

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);
        }/*from  w  ww  .  j a  va2  s. com*/
    } else {
        if (model.getSize() == 3) {
            model.removeElementAt(2);
        }
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java

public void updateAvailableConcepts() {
    if (!isUpdatingAvailableConcepts.get() && this.isExportMapping) {
        isUpdatingAvailableConcepts.set(true);
        try {//from  w w w.j  a v a  2  s. com
            List<SpExportSchemaItem> available = this.getAvailableConcepts();
            for (QueryFieldPanel qfp : queryFieldItems) {
                JComboBox bx = qfp.getSchemaItemCBX();
                if (bx != null) {
                    DefaultComboBoxModel bxm = (DefaultComboBoxModel) bx.getModel();
                    bxm.removeAllElements();
                    for (SpExportSchemaItem i : available) {
                        bxm.addElement(i);
                    }
                    SpExportSchemaItem qi = qfp.getSchemaItem();
                    if (qi != null && qi.getSpExportSchemaItemId() != null) {
                        SpExportSchemaItem unMappedItem = new SpExportSchemaItem();
                        unMappedItem.setFieldName(getResourceString("QueryBldrPane.UnmappedSchemaItemName"));
                        bxm.insertElementAt(unMappedItem, 0);
                        bxm.insertElementAt(qi, 1);
                        bx.setSelectedIndex(1);
                    } else {
                        //System.out.println("Setting unmapped concept field name to " + qfp.getExportedFieldName());
                        SpExportSchemaItem unMappedItem = new SpExportSchemaItem();
                        String expFldName = qfp.getExportedFieldName();
                        if (StringUtils.isBlank(expFldName)) {
                            if (available.size() > 0) {
                                unMappedItem.setFieldName(
                                        getResourceString("QueryBldrPane.UnmappedSchemaItemName"));
                            } else {
                                unMappedItem.setFieldName(qfp.getFieldTitle());
                            }
                        } else {
                            unMappedItem.setFieldName(expFldName);
                        }
                        bxm.insertElementAt(unMappedItem, 0);
                        bx.setSelectedIndex(0);
                    }
                    bx.setEditable(qi == null || qi.getSpExportSchemaItemId() == null);
                }
            }
        } finally {
            isUpdatingAvailableConcepts.set(false);
        }
    }
}

From source file:op.care.med.inventory.DlgCloseStock.java

private void initDialog() {
    String text = SYSTools.xx("nursingrecords.prescription.dlgCloseStock.youWantToClose1a") + medStock.getID()
            + SYSTools.xx("nursingrecords.prescription.dlgCloseStock.youWantToClose1b");
    text += "<br/>" + MedStockTools.getTextASHTML(medStock) + "</br>";
    text += "<br/>" + SYSTools.xx("nursingrecords.prescription.dlgCloseStock.chooseAReason") + ":";
    txtInfo.setContentType("text/html");
    txtInfo.setText(SYSTools.toHTML(SYSConst.html_div(text)));

    EntityManager em = OPDE.createEM();//from  w  ww  . jav  a 2  s  .co  m
    Query query = em.createQuery(" " + " SELECT b FROM MedStock b "
            + " WHERE b.inventory = :inventory AND b.out = :out AND b.opened = :opened "
            + " ORDER BY b.in, b.id ");

    query.setParameter("inventory", medStock.getInventory());
    query.setParameter("out", SYSConst.DATE_UNTIL_FURTHER_NOTICE);
    query.setParameter("opened", SYSConst.DATE_UNTIL_FURTHER_NOTICE);
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel(query.getResultList().toArray());
    dcbm.insertElementAt(SYSTools.xx("misc.msg.none"), 0);
    cmbBestID.setModel(dcbm);
    cmbBestID.setRenderer(new ListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList jList, Object o, int i, boolean b, boolean b1) {
            String text = o instanceof MedStock ? ((MedStock) o).getID().toString() : o.toString();
            return new JLabel(text);
        }
    });
    em.close();

    int index = Math.min(2, cmbBestID.getItemCount());
    cmbBestID.setSelectedIndex(index - 1);

    lblEinheiten.setText(SYSConst.UNITS[medStock.getTradeForm().getDosageForm().getPackUnit()] + " "
            + SYSTools.xx("misc.msg.usedup"));
    txtLetzte.setText("");
    txtLetzte.setEnabled(false);
    // Das mit dem Vorabstellen nur bei Formen, die auf Stck basieren also APV = 1
    rbStellen.setEnabled(medStock.getTradeForm().getDosageForm().getUPRState() == DosageFormTools.STATE_UPR1);
}

From source file:op.care.med.inventory.DlgNewStocks.java

private void initCmbVorrat() {

    if (ovrVorrat.getOverlayComponents().length > 0) {
        ovrVorrat.removeOverlayComponent(ovrVorrat.getOverlayComponents()[0]);
    }// ww w . j a  va 2  s  .c  o m

    if (resident != null) {
        //            ovrVorrat.removeOverlayComponent(ovrVorrat.getOverlayComponents()[0]);
        //            ovrVorrat.addOverlayComponent(questionIconVorrat, DefaultOverlayable.SOUTH_WEST);
        //

        cmbVorrat.setRenderer(MedInventoryTools.getInventoryRenderer());
        if (tradeForm == null) {
            cmbVorrat.setModel(new DefaultComboBoxModel());
            inventory = null;
        } else {
            List<MedInventory> vorraete = new ArrayList<MedInventory>();
            inventory = TradeFormTools.getInventory4TradeForm(resident, tradeForm);

            if (inventory == null) {
                vorraete = TradeFormTools.getSuitableInventoriesForThisTradeForm(resident, tradeForm);
            } else {
                vorraete.add(inventory);
            }
            cmbVorrat.setModel(new DefaultComboBoxModel(vorraete.toArray()));
        }

        //            ovrVorrat.removeOverlayComponent(ovrVorrat.getOverlayComponents()[0]);
        if (tradeForm != null) {
            if (inventory == null) {
                DefaultComboBoxModel dcbm = (DefaultComboBoxModel) cmbVorrat.getModel();
                dcbm.insertElementAt(new MedInventory(resident, "<AUTOMATISCH>"), 0);
                cmbVorrat.setSelectedIndex(0);

                if (dcbm.getSize() > 1) {
                    ovrVorrat.addOverlayComponent(attentionIconVorrat, DefaultOverlayable.SOUTH_WEST);
                    attentionIconVorrat.setToolTipText(
                            "<html>Keinen <b>exakt</b> passender Vorrat gefunden. Whlen Sie selbst einen passenden aus oder verwenden Sie <b>automatisch</b>.<html>");
                    cmbVorrat.showPopup();
                } else {
                    ovrVorrat.addOverlayComponent(infoIconVorrat, DefaultOverlayable.SOUTH_WEST);
                    infoIconVorrat
                            .setToolTipText("<html>Ein neuer Vorrat wird <b>automatisch</b> erstellt.</html>");
                }
            } else {
                correctIconVorrat.setToolTipText(null);
                ovrVorrat.addOverlayComponent(correctIconVorrat, DefaultOverlayable.SOUTH_WEST);
            }
        } else {
            ovrVorrat.addOverlayComponent(questionIconVorrat, DefaultOverlayable.SOUTH_WEST);
            questionIconVorrat.setToolTipText("<html>Kein Medikament ausgewhlt.<html>");
        }
    }
}