Example usage for javax.swing DefaultListModel contains

List of usage examples for javax.swing DefaultListModel contains

Introduction

In this page you can find the example usage for javax.swing DefaultListModel contains.

Prototype

public boolean contains(Object elem) 

Source Link

Document

Tests whether the specified object is a component in this list.

Usage

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultListModel model = new DefaultListModel();
    model.ensureCapacity(1000);/*from www. j  av  a 2  s .  c  o  m*/
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 5; j++) {
            model.addElement(labels[j]);
        }
    }
    System.out.println(model.contains("A"));

    JList jlist2 = new JList(model);
    jlist2.setVisibleRowCount(4);
    jlist2.setFixedCellHeight(12);
    jlist2.setFixedCellWidth(200);
    JScrollPane scrollPane2 = new JScrollPane(jlist2);
    frame.add(scrollPane2, BorderLayout.CENTER);

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

From source file:imageuploader.ImgWindow.java

private void jCB_ColorsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCB_ColorsActionPerformed
    // TODO add your handling code here:
    eventCounter++;//from  w w  w. j  a v  a 2 s . c o m

    if (evt.getActionCommand().equals("comboBoxChanged")) {

        if (jCB_Colors.getModel().getSize() > 0) {
            String a = jCB_Colors.getSelectedItem().toString();
            DefaultListModel listM = (DefaultListModel) jL_Info.getModel();

            if (eventCounter > 2) {

                if (listM.contains(a) == false) {
                    listM.addElement(a);
                    // boolean add = list.add(jCB_Colors.getSelectedItem().toString());
                }
            }

        }

    }

}

From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java

private void fireComandDataChangedEvent(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_fireComandDataChangedEvent
    parsedAttack = new Attack();
    List<Village> villages = PluginManager.getSingleton().executeVillageParser(jCommandArea.getText());
    if (villages == null || villages.isEmpty() || villages.size() < 2) {
        parsedAttack = null;//from   w  ww .ja v  a  2s  . c o m
    } else {
        Village source = villages.get(0);
        Village target = villages.get(1);
        if (jCommandArea.getText()
                .indexOf(PluginManager.getSingleton().getVariableValue("sos.arrive.time")) > -1) {
            //change village order for SOS requests
            source = villages.get(1);
            target = villages.get(0);
        }
        parsedAttack.setSource(source);
        parsedAttack.setTarget(target);

        Date arriveDate = null;
        try {
            String text = jCommandArea.getText();
            String arrive = null;
            String arriveLine = null;
            if (text.indexOf(PluginManager.getSingleton().getVariableValue("attack.arrive.time")) > -1) {
                String searchString = PluginManager.getSingleton().getVariableValue("attack.arrive.time");
                arriveLine = text.substring(
                        text.indexOf(PluginManager.getSingleton().getVariableValue("attack.arrive.time"))
                                + searchString.length());
            } else {
                String searchString = PluginManager.getSingleton().getVariableValue("sos.arrive.time");
                arriveLine = text.substring(
                        text.indexOf(PluginManager.getSingleton().getVariableValue("sos.arrive.time"))
                                + searchString.length());
            }

            StringTokenizer tokenizer = new StringTokenizer(arriveLine, "\n");
            String date = tokenizer.nextToken();
            arrive = date.trim();//arriveLine.trim();//date.trim() + " " + time.trim();
            SimpleDateFormat f = null;
            if (!ServerSettings.getSingleton().isMillisArrival()) {
                f = new SimpleDateFormat(PluginManager.getSingleton().getVariableValue("sos.date.format"));
            } else {
                f = new SimpleDateFormat(PluginManager.getSingleton().getVariableValue("sos.date.format.ms"));
            }
            arriveDate = f.parse(arrive);
            parsedAttack.setArriveTime(arriveDate);
            if (arriveDate == null) {
                throw new Exception("Invalid arrive");
            }
        } catch (Exception ignored) {
            parsedAttack = null;
        }
        //calc possible units
        double dist = DSCalculator.calculateDistance(source, target);
        String[] units = new String[] { "axe", "sword", "spy", "light", "heavy", "ram", "knight", "snob" };
        DefaultListModel model = new DefaultListModel();
        for (String unit : units) {
            UnitHolder unitHolder = DataHolder.getSingleton().getUnitByPlainName(unit);
            if (unit != null) {
                long dur = (long) Math.floor(dist * unitHolder.getSpeed() * 60000.0);
                if (arriveDate.getTime() - dur <= System.currentTimeMillis()) {
                    model.addElement(unitHolder);
                }
            }
        }

        if (model.isEmpty()) {
            //no element 
            parsedAttack = null;
        }
        jPossibleUnits.setModel(model);

        UnitHolder ram = DataHolder.getSingleton().getUnitByPlainName("ram");
        UnitHolder axe = DataHolder.getSingleton().getUnitByPlainName("axe");
        UnitHolder spy = DataHolder.getSingleton().getUnitByPlainName("spy");
        if (model.contains(ram)) {
            jPossibleUnits.setSelectedValue(ram, true);
        } else if (model.contains(axe)) {
            jPossibleUnits.setSelectedValue(axe, true);
        } else {
            jPossibleUnits.setSelectedValue(spy, true);
        }
    }
    updateAttackBBView();
}

From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ApplicationProperties.java

private void interpretFont() {
    isSystemChange = true;/*from  ww  w.ja  v  a2s  .c o  m*/
    final DefaultListModel model = (DefaultListModel) lstSize.getModel();
    final String size = String.format("%d", theStandardFont.getSize());
    if (model.contains(size)) {
        lstSize.setSelectedValue(size, true);
    } else {
        lstSize.clearSelection();
    }
    txtFontSize.setText(String.format("%d", theStandardFont.getSize()));
    lstFont.setSelectedValue(theStandardFont.getFontName(), true);
    if (theStandardFont.isBold()) {
        if (theStandardFont.isItalic()) {
            lstStyle.setSelectedValue("Bold Italic", true);
        } else {
            lstStyle.setSelectedValue("Bold", true);
        }
    } else if (theStandardFont.isItalic()) {
        lstStyle.setSelectedValue("Italic", true);
    } else {
        lstStyle.setSelectedValue("Plain", true);
    }
    txtFontStyle.setText((String) lstStyle.getSelectedValue());
    txtFont.setText((String) lstFont.getSelectedValue());
    isSystemChange = false;
}

From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ApplicationProperties.java

private void updateFontSize() {
    if (!isSystemChange) {
        isSystemChange = true;//  w ww. j  ava2 s  .  c  o m
        final DefaultListModel model = (DefaultListModel) lstSize.getModel();
        if (model.contains(txtFontSize.getText())) {
            lstSize.setSelectedValue(txtFontSize.getText(), true);
        } else {
            lstSize.clearSelection();
        }
        setNewFont();
        isSystemChange = false;
    }
}

From source file:org.n52.ifgicopter.spf.output.GpxOutputPlugin.java

/**
 * /*w w w . j  av  a2s.  com*/
 */
protected void updateGUI() {
    if (this.gpx == null)
        return;

    final String t = this.gpx.xmlText(GPX_OPTIONS);
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            GpxOutputPlugin.this.textPane.setText(t);

            GpxOutputPlugin.this.outputFileLabel
                    .setText("<html><b>Output file: </b>" + getGpxFilePath() + "</html>");

            DefaultListModel model = (DefaultListModel) GpxOutputPlugin.this.valuesToSaveList.getModel();
            // update list
            if (model.getSize() < GpxOutputPlugin.this.availableDataKeys.size()) {
                if (model.contains(NO_DATA_LIST_ELEMENT))
                    model.remove(model.indexOf(NO_DATA_LIST_ELEMENT));

                for (String s : GpxOutputPlugin.this.availableDataKeys) {
                    if (!model.contains(s)) {
                        model.addElement(s);
                    }
                }
            }
        }
    });
}

From source file:org.opendatakit.briefcase.ui.CharsetConverterDialog.java

protected void initialize() {
    DefaultListModel<CharsetEntry> defaultListModel = new DefaultListModel<CharsetEntry>();

    for (CharsetEntry commonCharsetEntry : commonCharsetEntries) {
        try {/*from w  w w  . jav  a2  s.c o m*/
            if (Charset.isSupported(commonCharsetEntry.getCharsetName())) {
                defaultListModel.addElement(commonCharsetEntry);
            }
        } catch (IllegalCharsetNameException e) {
            // just ignore it. It will happen for "Mac OS Roman" under Windows
        }
    }

    SortedMap<String, Charset> charsetSortedMap = Charset.availableCharsets();
    for (Map.Entry<String, Charset> charsetMapEntry : charsetSortedMap.entrySet()) {
        CharsetEntry charsetEntry = new CharsetEntry(charsetMapEntry.getValue().displayName(),
                charsetMapEntry.getKey());
        if (!defaultListModel.contains(charsetEntry)) {
            defaultListModel.addElement(charsetEntry);
        }
    }

    listCharset.setModel(defaultListModel);

    if (defaultListModel.size() > 0) {
        listCharset.setSelectedIndex(0);

        listCharset.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                updatePreview();
            }
        });
    } else {
        JOptionPane.showMessageDialog(this,
                "It appears that your installed Java Runtime Environment does not support any charset encodings!",
                "Error!", JOptionPane.ERROR_MESSAGE);
    }
}