Example usage for javax.swing DefaultComboBoxModel getIndexOf

List of usage examples for javax.swing DefaultComboBoxModel getIndexOf

Introduction

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

Prototype

public int getIndexOf(Object anObject) 

Source Link

Document

Returns the index-position of the specified object in the list.

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);/*from  ww w .j a v  a 2 s. co  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");
            System.out.println(model.getIndexOf("A"));
        }
    };
    button.addActionListener(actionListener);

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

From source file:Main.java

@Override
public Object getCellEditorValue() {
    Object o = super.getCellEditorValue();
    DefaultComboBoxModel<String> m = (DefaultComboBoxModel<String>) comboBox.getModel();
    Node n = new Node(ValueName.getText(), node.getValues());
    n.setIndex(m.getIndexOf(o));
    return n;/*from  ww w.  j  ava 2s .  c  om*/
}

From source file:io.github.jeddict.jpa.modeler.properties.named.nativequery.NamedNativeQueryPanel.java

private void addResultClass(String resultClass) {
    DefaultComboBoxModel model = (DefaultComboBoxModel) resultClass_jComboBox.getModel();
    String unqualifiedClassName = getClassName(resultClass);
    if (model.getIndexOf(unqualifiedClassName) != -1) { // check if it is Entity then select
        resultClass_jComboBox.setSelectedItem(unqualifiedClassName);
    } else { //if other class
        if (model.getIndexOf(resultClass) == -1) {
            model.addElement(resultClass);
        }//from   ww w.  j a va 2  s.c o m
        resultClass_jComboBox.setSelectedItem(resultClass);
    }
}

From source file:com.mirth.connect.client.ui.panels.connectors.ResponseSettingsPanel.java

private void setSelectedItem(Object selectedItem) {
    DefaultComboBoxModel model = (DefaultComboBoxModel) responseComboBox.getModel();

    if (selectedItem instanceof Entry) {
        /*/*from   w ww  .j a v  a2 s  .c o m*/
         * If the selected item is an Entry and the key ("d#") is the same
         * as an Entry in the model, then they're "the same", and that entry
         * is selected.
         */
        for (int i = 0; i <= model.getSize() - 1; i++) {
            if (model.getElementAt(i) instanceof Entry && ((Entry<String, String>) selectedItem).getKey()
                    .equals(((Entry<String, String>) model.getElementAt(i)).getKey())) {
                responseComboBox.setSelectedIndex(i);
                return;
            }
        }
    } else if (model.getIndexOf(selectedItem) >= 0) {
        responseComboBox.setSelectedItem(selectedItem);
        return;
    }
    responseComboBox.setSelectedIndex(0);
}

From source file:com.mirth.connect.client.ui.panels.connectors.SourceSettingsPanel.java

private void setSelectedItem(Object selectedItem) {
    DefaultComboBoxModel model = (DefaultComboBoxModel) responseComboBox.getModel();

    if (selectedItem instanceof Entry) {
        /*/*from ww  w  .ja v a2 s. c o  m*/
         * If the selected item is an Entry and the key ("d#") is the same as an Entry in the
         * model, then they're "the same", and that entry is selected.
         */
        for (int i = 0; i <= model.getSize() - 1; i++) {
            if (model.getElementAt(i) instanceof Entry && ((Entry<String, String>) selectedItem).getKey()
                    .equals(((Entry<String, String>) model.getElementAt(i)).getKey())) {
                responseComboBox.setSelectedIndex(i);
                return;
            }
        }
    } else if (model.getIndexOf(selectedItem) >= 0) {
        responseComboBox.setSelectedItem(selectedItem);
        return;
    }
    responseComboBox.setSelectedIndex(0);
}

From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java

/**
 * Creates new form MapFrame//  ww  w  .  j  a va  2s  . c om
 */
DSWorkbenchMainFrame() {
    initComponents();
    setAlwaysOnTop(false);
    if (!GlobalOptions.isMinimal()) {
        setTitle("DS Workbench " + Constants.VERSION + Constants.VERSION_ADDITION);
    } else {
        setTitle("DS Workbench Mini " + Constants.VERSION + Constants.VERSION_ADDITION);
    }

    jExportDialog.pack();
    jAddROIDialog.pack();

    JOutlookBar outlookBar = new JOutlookBar();
    outlookBar.addBar("Navigation", jNavigationPanel);
    outlookBar.addBar("Information", jInformationPanel);
    outlookBar.addBar("Karte", jMapPanel);
    outlookBar.addBar("ROI", jROIPanel);
    outlookBar.setVisibleBar(1);
    jSettingsScrollPane.setViewportView(outlookBar);

    mAbout = new AboutDialog(this, true);
    mAbout.pack();
    chooser.setDialogTitle("Speichern unter...");
    chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {

        @Override
        public boolean accept(File f) {
            return (f != null) && (f.isDirectory() || f.getName().endsWith(".png"));
        }

        @Override
        public String getDescription() {
            return "PNG Image (*.png)";
        }
    });

    chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {

        @Override
        public boolean accept(File f) {
            return (f != null) && (f.isDirectory() || f.getName().endsWith(".jpeg"));
        }

        @Override
        public String getDescription() {
            return "JPEG Image (*.jpeg)";
        }
    });

    //Schedule Backup
    new Timer("BackupTimer", true).schedule(new BackupTask(), 60 * 10000, 60 * 10000);

    //give focus to map panel if mouse enters map
    jMapPanelHolder.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            jMapPanelHolder.requestFocusInWindow();
        }
    });

    getContentPane().setBackground(Constants.DS_BACK);
    pack();
    capabilityInfoPanel1.addActionListener(MapPanel.getSingleton());

    // <editor-fold defaultstate="collapsed" desc=" Add global KeyListener ">
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

        @Override
        public void eventDispatched(AWTEvent event) {
            if (event.getID() == KeyEvent.KEY_PRESSED) {
                KeyEvent e = (KeyEvent) event;
                if (DSWorkbenchMainFrame.getSingleton().isActive()) {
                    //move shortcuts
                    if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                        scroll(0.0, 2.0);
                    } else if (e.getKeyCode() == KeyEvent.VK_UP) {
                        scroll(0.0, -2.0);
                    } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                        scroll(-2.0, 0.0);
                    } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                        scroll(2.0, 0.0);
                    } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //shot minimap tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_AXE);
                    } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack axe tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_RAM);
                    } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack ram tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SNOB);
                    } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack snob tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SPY);
                    } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack sword tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_LIGHT);
                    } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack light tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_HEAVY);
                    } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack heavy tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SWORD);
                    } else if ((e.getKeyCode() == KeyEvent.VK_S) && e.isControlDown() && !e.isAltDown()) {
                        //search frame shortcut
                        DSWorkbenchSearchFrame.getSingleton()
                                .setVisible(!DSWorkbenchSearchFrame.getSingleton().isVisible());
                    }
                }

                //misc shortcuts
                if ((e.getKeyCode() == KeyEvent.VK_0) && e.isAltDown()) {
                    //no tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_DEFAULT);
                } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //measure tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MEASURE);
                } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //mark tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MARK);
                } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //tag tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_TAG);
                } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SUPPORT);
                } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SELECTION);
                } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_RADAR);
                } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_INGAME);
                } else if ((e.getKeyCode() == KeyEvent.VK_8) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //res ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SEND_RES_INGAME);
                } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //move minimap tool shortcut
                    MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MOVE);
                } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //zoom minimap tool shortcut
                    MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ZOOM);
                } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //shot minimap tool shortcut
                    MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SHOT);
                } else if ((e.getKeyCode() == KeyEvent.VK_T) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //search time shortcut
                    ClockFrame.getSingleton().setVisible(!ClockFrame.getSingleton().isVisible());
                } else if ((e.getKeyCode() == KeyEvent.VK_S) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    planMapshot();
                } else if (e.getKeyCode() == KeyEvent.VK_F2) {
                    DSWorkbenchAttackFrame.getSingleton()
                            .setVisible(!DSWorkbenchAttackFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F3) {
                    DSWorkbenchMarkerFrame.getSingleton()
                            .setVisible(!DSWorkbenchMarkerFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F4) {
                    DSWorkbenchTroopsFrame.getSingleton()
                            .setVisible(!DSWorkbenchTroopsFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F5) {
                    DSWorkbenchRankFrame.getSingleton()
                            .setVisible(!DSWorkbenchRankFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F6) {
                    DSWorkbenchFormFrame.getSingleton()
                            .setVisible(!DSWorkbenchFormFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F7) {
                    if (ServerSettings.getSingleton().isChurch()) {
                        DSWorkbenchChurchFrame.getSingleton()
                                .setVisible(!DSWorkbenchChurchFrame.getSingleton().isVisible());
                    }
                } else if (e.getKeyCode() == KeyEvent.VK_F8) {
                    DSWorkbenchConquersFrame.getSingleton()
                            .setVisible(!DSWorkbenchConquersFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F9) {
                    DSWorkbenchNotepad.getSingleton()
                            .setVisible(!DSWorkbenchNotepad.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F10) {
                    DSWorkbenchTagFrame.getSingleton()
                            .setVisible(!DSWorkbenchTagFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F11) {
                    DSWorkbenchStatsFrame.getSingleton()
                            .setVisible(!DSWorkbenchStatsFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F12) {
                    DSWorkbenchSettingsDialog.getSingleton().setVisible(true);
                } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 1
                    centerROI(0);
                } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 2
                    centerROI(1);
                } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 3
                    centerROI(2);
                } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 4
                    centerROI(3);
                } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 5
                    centerROI(4);
                } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 6
                    centerROI(5);
                } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 7
                    centerROI(6);
                } else if ((e.getKeyCode() == KeyEvent.VK_8) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 8
                    centerROI(7);
                } else if ((e.getKeyCode() == KeyEvent.VK_9) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 9
                    centerROI(8);
                } else if ((e.getKeyCode() == KeyEvent.VK_0) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 10
                    centerROI(9);
                } else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                    jMapPanelHolder.requestFocusInWindow();
                    MapPanel.getSingleton().setSpaceDown(true);
                } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
                    jMapPanelHolder.requestFocusInWindow();
                    MapPanel.getSingleton().setShiftDown(true);
                }
            } else if (event.getID() == KeyEvent.KEY_RELEASED) {
                KeyEvent e = (KeyEvent) event;
                if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                    MapPanel.getSingleton().setSpaceDown(false);
                } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
                    MapPanel.getSingleton().setShiftDown(false);
                }
            }
        }
    }, AWTEvent.KEY_EVENT_MASK);
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Load UI Icons ">
    try {
        jOnlineLabel.setIcon(new ImageIcon("./graphics/icons/online.png"));
        jEnableClipboardWatchButton.setIcon(new ImageIcon("./graphics/icons/watch_clipboard.png"));
        jCenterIngameButton
                .setIcon(new ImageIcon(DSWorkbenchMainFrame.class.getResource("/res/ui/center_ingame.png")));
        jRefreshButton.setIcon(new ImageIcon("./graphics/icons/refresh.png"));
        jCenterCoordinateIngame.setIcon(new ImageIcon("./graphics/icons/center.png"));
    } catch (Exception e) {
        logger.error("Failed to load status icon(s)", e);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Check for desktop support ">
    if (!Desktop.isDesktopSupported()) {
        jCenterIngameButton.setEnabled(false);
        jCenterCoordinateIngame.setEnabled(false);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Restore last map position ">
    try {
        String x = GlobalOptions.getSelectedProfile().getProperty("last.x");
        String y = GlobalOptions.getSelectedProfile().getProperty("last.y");
        centerPosition(Double.parseDouble(x), Double.parseDouble(y));
    } catch (Exception e) {
        centerPosition(ServerSettings.getSingleton().getMapDimension().getCenterX(),
                ServerSettings.getSingleton().getMapDimension().getCenterY());
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Restore other settings ">
    jShowMapPopup.setSelected(GlobalOptions.getProperties().getBoolean("show.map.popup"));
    jShowMouseOverInfo.setSelected(GlobalOptions.getProperties().getBoolean("show.mouseover.info"));
    jIncludeSupport.setSelected(GlobalOptions.getProperties().getBoolean("include.support"));
    jHighlightTribeVillages.setSelected(GlobalOptions.getProperties().getBoolean("highlight.tribes.villages"));
    jShowRuler.setSelected(GlobalOptions.getProperties().getBoolean("show.ruler"));
    jDisplayChurch.setSelected(GlobalOptions.getProperties().getBoolean("show.church"));
    jDisplayWatchtower.setSelected(GlobalOptions.getProperties().getBoolean("show.watchtower"));
    jDisplayChurch.setEnabled(ServerSettings.getSingleton().isChurch());
    jDisplayWatchtower.setEnabled(ServerSettings.getSingleton().isWatchtower());
    ServerSettings.getSingleton().addListener(new ServerSettingsListener() {
        @Override
        public void fireServerSettingsChanged() {
            jDisplayChurch.setEnabled(ServerSettings.getSingleton().isChurch());
            jDisplayWatchtower.setEnabled(ServerSettings.getSingleton().isWatchtower());
        }
    });
    int r = GlobalOptions.getProperties().getInt("radar.size");
    int hour = r / 60;
    jHourField.setText(Integer.toString(hour));
    jMinuteField.setText(Integer.toString(r - hour * 60));
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Skin Setup">
    DefaultComboBoxModel gpModel = new DefaultComboBoxModel(GlobalOptions.getAvailableSkins());
    jGraphicPacks.setModel(gpModel);
    String skin = GlobalOptions.getProperty("default.skin");
    if (gpModel.getIndexOf(skin) != -1) {
        jGraphicPacks.setSelectedItem(skin);
    } else {
        jGraphicPacks.setSelectedItem("default");
    }
    //</editor-fold>

    minZoom = GlobalOptions.getProperties().getDouble("map.zoom.min");
    maxZoom = GlobalOptions.getProperties().getDouble("map.zoom.max");
    dZoomInOutFactor = GlobalOptions.getProperties().getDouble("map.zoom.in.out.factor");

    mNotificationHideThread = new NotificationHideThread();
    mNotificationHideThread.start();
    SystrayHelper.installSystrayIcon();
    //update online state
    onlineStateChanged();
    restoreProperties();
}

From source file:org.netbeans.jpa.modeler.properties.named.nativequery.NamedNativeQueryPanel.java

private void addResultClass(String resultClass) {
    DefaultComboBoxModel model = (DefaultComboBoxModel) resultClass_jComboBox.getModel();
    String unqualifiedClassName = SourceGroupSupport.getClassName(resultClass);
    if (model.getIndexOf(unqualifiedClassName) != -1) { // check if it is Entity then select
        resultClass_jComboBox.setSelectedItem(unqualifiedClassName);
    } else { //if other class
        if (model.getIndexOf(resultClass) == -1) {
            model.addElement(resultClass);
        }/*w  ww.j  a  va2 s  .  c o m*/
        resultClass_jComboBox.setSelectedItem(resultClass);
    }
}

From source file:org.nuclos.client.ui.collect.component.CollectableComboBox.java

@Override
protected void updateView(CollectableField clctfValue) {
    if (hasAdditionalEntry()) {
        removeAdditionalEntry();/*ww w  .  j  a  va  2 s.  co m*/
    }

    final JComboBox cb = getJComboBox();
    final DefaultComboBoxModel cbm = getDefaultComboBoxModel();

    int iIndex = cbm.getIndexOf(clctfValue);
    // If the value could not be found, it might be the mnemonic, so look for the value id
    if (iIndex < 0 && clctfValue.isIdField() && clctfValue.getValueId() != null) {
        for (int i = 0; i < cbm.getSize(); i++) {
            final CollectableField cf = (CollectableField) cbm.getElementAt(i);
            if (!cf.isIdField())
                continue;
            final Long valueId = IdUtils.toLongId(cf.getValueId());
            final Long vid = IdUtils.toLongId(clctfValue.getValueId());
            if (LangUtils.equals(vid, valueId)) {
                iIndex = i;
                break;
            }
        }
    }
    if (iIndex >= 0) {
        cb.setSelectedIndex(iIndex);
        // Note that setSelectedItem doesn't work here, as clctf might have no label.
    } else {
        assert iIndex == -1;

        final Long vid = !clctfValue.isIdField() ? null : IdUtils.toLongId(clctfValue.getValueId());
        Long oValueId = null;
        if (clctfValue.isIdField()) {
            oValueId = vid;
            // sbWarning.append(" (Id: ").append(oValueId).append(")");
        }

        if (isInsertable() && (oValueId == null) && (vid != null)) {
            final String sText = clctfValue.toString();
            cb.setSelectedItem(sText);
        } else {
            addAdditionalEntry(clctfValue);
            cb.setSelectedIndex(cbm.getIndexOf(clctfValue));
        }
    }
}

From source file:pl.otros.logview.gui.LogViewPanel.java

protected void initMessageDetailsToolbar() {
    final JButton buttonFormatters = new JButton("Message formatters", Icons.MESSAGE_FORMATTER);
    buttonFormatters.addMouseListener(new MouseAdapter() {

        @Override//from w  ww.  ja v a2s  .c o  m
        public void mouseClicked(MouseEvent e) {
            showMessageFormatterOrColorizerPopupMenu(e, "Message formatters",
                    selectedMessageFormattersContainer, messageFormattersContainer);
        }
    });
    buttonFormatters.setToolTipText("Select used message formatters");
    messageDetailToolbar.add(buttonFormatters);

    final JButton buttonColorizers = new JButton("Message colorizers", Icons.MESSAGE_COLORIZER);
    buttonColorizers.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            showMessageFormatterOrColorizerPopupMenu(e, "Message colorizers",
                    selectedMessageColorizersContainer, messageColorizersContainer);
        }
    });
    buttonColorizers.setToolTipText("Select used message colorizers");
    messageDetailToolbar.add(buttonColorizers);
    messageDetailToolbar.add(new CopyStyledMessageDetailAction(otrosApplication, dateFormat,
            selectedMessageColorizersContainer, selectedMessageFormattersContainer));

    messageDetailToolbar.add(new JLabel("Maximum message size for format"));

    final DefaultComboBoxModel defaultComboBoxModel = new DefaultComboBoxModel(new String[] {});
    String[] values = new String[] { "10kB", "100kB", "200kB", "300kB", "400kB", "500kB", "600kB", "700kB",
            "800kB", "900kB", "1MB", "2MB", "3MB", "4MB", "5MB" };
    for (String value : values) {
        defaultComboBoxModel.addElement(value);
    }
    final JXComboBox messageMaximumSize = new JXComboBox(defaultComboBoxModel);
    messageMaximumSize.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String max = (String) defaultComboBoxModel.getElementAt(messageMaximumSize.getSelectedIndex());
            configuration.setProperty(ConfKeys.MESSAGE_FORMATTER_MAX_SIZE, max);
            messageDetailListener.setMaximumMessageSize((int) new FileSize(max).getBytes());

        }
    });

    messageMaximumSize.setEditable(false);
    AutoCompleteDecorator.decorate(messageMaximumSize);
    messageMaximumSize.setMaximumSize(new Dimension(100, 50));
    messageDetailToolbar.add(messageMaximumSize);
    String messageMaxSize = configuration.getString(ConfKeys.MESSAGE_FORMATTER_MAX_SIZE,
            (String) defaultComboBoxModel.getElementAt(messageMaximumSize.getSelectedIndex()));
    if (defaultComboBoxModel.getIndexOf(messageMaxSize) >= 0) {
        messageMaximumSize.setSelectedItem(messageMaxSize);
    }

}

From source file:se.trixon.jota.client.ui.MainFrame.java

private void requestConnect() throws NotBoundException {
    String[] hosts = mOptions.getHosts().split(";");
    Arrays.sort(hosts);/*from  w w w . j a  v a 2s.co m*/
    DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(hosts);
    JComboBox hostComboBox = new JComboBox(comboBoxModel);
    hostComboBox.setEditable(true);

    hostComboBox.setSelectedItem(mClient.getHost());
    JTextField portTextField = new JTextField(String.valueOf(mClient.getPortHost()));
    final JComponent[] inputs = new JComponent[] { new JLabel(Dict.HOST.toString()), hostComboBox,
            new JLabel(Dict.PORT.toString()), portTextField, };

    Object[] options = { Dict.CONNECT.toString(), Dict.CANCEL.toString() };
    int retval = JOptionPane.showOptionDialog(this, inputs, Dict.CONNECT_TO_HOST.toString(),
            JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);

    if (retval == 0) {
        String currentHost = mClient.getHost();
        int currentPort = mClient.getPortHost();
        String host = (String) hostComboBox.getSelectedItem();
        String portString = portTextField.getText();

        try {
            int port = Integer.valueOf(portString);
            mManager.disconnect();
            mManager.connect(host, port);

            if (comboBoxModel.getIndexOf(host) == -1) {
                comboBoxModel.addElement(host);
            }
            mOptions.setHosts(SwingHelper.comboBoxModelToString(comboBoxModel));
        } catch (NumberFormatException e) {
            Message.error(this, Dict.ERROR.toString(), String.format(Dict.INVALID_PORT.toString(), portString));
        } catch (NotBoundException | MalformedURLException | RemoteException | SocketException ex) {
            Message.error(this, Dict.ERROR.toString(), ex.getLocalizedMessage());
            mClient.setHost(currentHost);
            mClient.setPortHost(currentPort);
        }
    }
}