Example usage for javax.swing JList getSelectedValue

List of usage examples for javax.swing JList getSelectedValue

Introduction

In this page you can find the example usage for javax.swing JList getSelectedValue.

Prototype

@BeanProperty(bound = false)
public E getSelectedValue() 

Source Link

Document

Returns the value for the smallest selected cell index; the selected value when only a single item is selected in the list.

Usage

From source file:com.konifar.material_icon_generator.MaterialDesignIconGenerateDialog.java

private void initColorComboBox() {
    comboBoxColor.addActionListener(new ActionListener() {
        @Override/*  w ww  .  ja va 2 s.c  o m*/
        public void actionPerformed(ActionEvent event) {
            model.setColorAndFileName((String) comboBoxColor.getSelectedItem());
            textFieldFileName.setText(model.getFileName());
            showIconPreview();
        }
    });

    comboBoxColor.getAccessibleContext().addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (AccessibleContext.ACCESSIBLE_STATE_PROPERTY.equals(event.getPropertyName())
                    && AccessibleState.FOCUSED.equals(event.getNewValue())
                    && comboBoxColor.getAccessibleContext().getAccessibleChild(0) instanceof ComboPopup) {
                ComboPopup popup = (ComboPopup) comboBoxColor.getAccessibleContext().getAccessibleChild(0);
                JList list = popup.getList();
                comboBoxColor.setSelectedItem(String.valueOf(list.getSelectedValue()));
            }
        }
    });
}

From source file:com.starbucks.apps.StarbucksBarista.java

private void ordersListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_ordersListValueChanged
    JList list = (JList) evt.getSource();
    Order order = (Order) list.getSelectedValue();
    if (order != null) {
        viewButton.setEnabled(true);/*from w  w w. ja va 2  s.co  m*/
        prepareButton.setEnabled(true);
    }
}

From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java

private void pickListAddAction(final JList sourceList, final JList destinationList) {
    if (sourceList.getSelectedValue() != null) {
        final Object element = sourceList.getSelectedValue();
        ((DefaultListModel) sourceList.getModel()).remove(sourceList.getSelectedIndex());
        ((DefaultListModel) destinationList.getModel()).addElement(element);
    }//  www.j a v a2 s .  com
}

From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java

private void pickListRemoveAction(final JList sourceList, final JList destinationList) {
    if (sourceList.getSelectedValue() != null) {
        final Object element = sourceList.getSelectedValue();
        ((DefaultListModel) sourceList.getModel()).remove(sourceList.getSelectedIndex());
        ((DefaultListModel) destinationList.getModel()).addElement(element);
    }//from   www.j av a2 s  .com
}

From source file:gtu._work.ui.JarFinderUI.java

private void jList1MouseClicked(MouseEvent evt) {
    if (evt.getClickCount() != 2) {
        return;//from   w  w  w. j  av  a 2 s  . c o m
    }

    try {
        JList list = (JList) evt.getSource();

        StringBuilder sb = new StringBuilder("''jar\r\n'?'\r\n");
        String fileName = (String) list.getSelectedValue();

        ClipboardUtil.getInstance().setContents(fileName);

        int linecount = 0;
        for (String clz : jarfinder.getMap().get(fileName)) {
            if (linecount == 10) {
                sb.append("...?");
                break;
            }
            sb.append(clz + "\r\n");
            linecount++;
        }

        ComfirmDialogResult result = JOptionPaneUtil.newInstance().iconInformationMessage()
                .confirmButtonYesNoCancel().showConfirmDialog(sb, fileName);

        String jdGuiExe = StringUtils.trimToEmpty(jdGuiText.getText());
        if (result == ComfirmDialogResult.YES_OK_OPTION) {
            if (OsInfoUtil.isWindows()) {
                RuntimeBatPromptModeUtil.newInstance()
                        .command(String.format("cmd /c call \"%s\" \"%s\"", jdGuiExe, fileName)).apply();
            } else {
                RuntimeBatPromptModeUtil.newInstance()
                        .command(String.format("java -jar \"%s\" \"%s\"", jdGuiExe, fileName)).apply();
            }
        }

        if (result == ComfirmDialogResult.NO_OPTION) {
            DesktopUtil.openDir(new File(fileName).getParentFile());
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        // JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(ex.getMessage(),
        // "error");
        JCommonUtil.handleException(ex);
    }
}

From source file:fr.eurecom.hybris.demogui.HybrisDemoGui.java

public void keyReleased(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_DELETE) {

        JList<String> jlist = (JList<String>) e.getComponent();
        if (jlist.getSelectedIndex() >= 0) {

            if (jlist.equals(lstAmazon)) {
                new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.AWS,
                        jlist.getSelectedValue(), null)).start();
                System.out.println("Removed " + jlist.getSelectedValue() + " from Amazon S3.");
                corruptedItems.remove("amazon" + jlist.getSelectedValue());
            } else if (jlist.equals(lstAzure)) {
                new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.AZURE,
                        jlist.getSelectedValue(), null)).start();
                System.out.println("Removed " + jlist.getSelectedValue() + " from Azure.");
                corruptedItems.remove("azure" + jlist.getSelectedValue());
            } else if (jlist.equals(lstGoogle)) {
                new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.GOOGLE,
                        jlist.getSelectedValue(), null)).start();
                System.out.println("Removed " + jlist.getSelectedValue() + " from Google.");
                corruptedItems.remove("google" + jlist.getSelectedValue());
            } else if (jlist.equals(lstRackspace)) {
                new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.RACKSPACE,
                        jlist.getSelectedValue(), null)).start();
                System.out.println("Removed " + jlist.getSelectedValue() + " from Rackspace.");
                corruptedItems.remove("rackspace" + jlist.getSelectedValue());
            } else if (jlist.equals(lstHybris)) {
                new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.HYBRIS,
                        jlist.getSelectedValue(), null)).start();
                System.out.println("Removed " + jlist.getSelectedValue() + " from Hybris.");
            }/*from  w w  w. j av  a  2  s  .  co  m*/
        }
    } else if (e.getKeyChar() == 'c') {
        JList<String> jlist = (JList<String>) e.getComponent();
        if (jlist.getSelectedIndex() >= 0) {

            byte[] corruptedPayload = "I_AM_THE_BOGUS_PAYLOAD".getBytes();

            if (jlist.equals(lstAmazon)) {
                JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Amazon S3.",
                        "Corruption", JOptionPane.WARNING_MESSAGE);
                System.out.println("Corrupted " + jlist.getSelectedValue() + " on Amazon S3.");
                corruptedItems.add("amazon" + jlist.getSelectedValue());
                new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.AWS, jlist.getSelectedValue(),
                        corruptedPayload)).start();
            } else if (jlist.equals(lstAzure)) {
                System.out.println("Corrupted " + jlist.getSelectedValue() + " on Azure.");
                JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Azure.",
                        "Corruption", JOptionPane.WARNING_MESSAGE);
                corruptedItems.add("azure" + jlist.getSelectedValue());
                new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.AZURE,
                        jlist.getSelectedValue(), corruptedPayload)).start();
            } else if (jlist.equals(lstGoogle)) {
                JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Google.",
                        "Corruption", JOptionPane.WARNING_MESSAGE);
                System.out.println("Corrupted " + jlist.getSelectedValue() + " on Google.");
                corruptedItems.add("google" + jlist.getSelectedValue());
                new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.GOOGLE,
                        jlist.getSelectedValue(), corruptedPayload)).start();
            } else if (jlist.equals(lstRackspace)) {
                JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Rackspace.",
                        "Corruption", JOptionPane.WARNING_MESSAGE);
                System.out.println("Corrupted " + jlist.getSelectedValue() + " on Rackspace.");
                corruptedItems.add("rackspace" + jlist.getSelectedValue());
                new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.RACKSPACE,
                        jlist.getSelectedValue(), corruptedPayload)).start();
            }
        }
    }
}

From source file:csh.vctt.launcher.Launcher.java

/**
 * Prompt the user to select their character from a dialog.
 * @return Unique id number of the selected character.
 *//* w  w w  .  ja  va 2s.  c o  m*/
private String getPlayerSelection() {
    String selectedId = "-1";

    String outfitMembersJson = DataManager.execQuery(DataManager.M_OUTFITMEMBER_SELECT_QUERY);
    List<Player> outfitMembers = DataManager.getOutfitMembers(outfitMembersJson);
    Object[] outfitMembersArrObj = outfitMembers.toArray();
    Player[] outfitMembersArr = new Player[outfitMembersArrObj.length];
    for (int i = 0; i < outfitMembersArrObj.length; i++) {
        outfitMembersArr[i] = (Player) outfitMembersArrObj[i];
    }

    JList<Player> memSelList = new JList<Player>(outfitMembersArr);
    memSelList.setVisibleRowCount(10);

    JScrollPane memScrollPane = new JScrollPane(memSelList);
    memScrollPane.setPreferredSize(new Dimension(200, 400));

    int userAction = JOptionPane.showConfirmDialog(null, memScrollPane, "Select Character and Press Ok",
            JOptionPane.PLAIN_MESSAGE);

    Player selectedPlayer = null;
    if (userAction == JOptionPane.YES_OPTION) {
        selectedPlayer = memSelList.getSelectedValue();
    }

    if (selectedPlayer != null) {
        selectedId = selectedPlayer.getId();
    }

    return selectedId;
}

From source file:com.wesley.urban_cuts.client.urbancuts.myFrame.java

/**
 * Creates new form HomeFrame// w  w w  .j a v  a  2s.c om
 */
public myFrame() {
    initComponents();
    ctx = new ClassPathXmlApplicationContext(
            "classpath:com/wesley/urban_cuts/app/conf/applicationContext-*.xml");
    staffCrudService = (StaffCrudService) ctx.getBean("StaffCrudService");
    styleCrudService = (StyleCrudService) ctx.getBean("StyleCrudService");
    paymentCrudService = (PaymentCrudService) ctx.getBean("PaymentCrudService");

    populate_barbers();
    populate_styles();
    populate_table();

    jList2.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            if (!event.getValueIsAdjusting()) {
                JList source = (JList) event.getSource();
                String selected = source.getSelectedValue().toString();
                jTextField1.setText(selected);
            }
        }
    });

    jList3.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            if (!event.getValueIsAdjusting()) {
                JList source = (JList) event.getSource();
                String selected2 = source.getSelectedValue().toString();
                jTextField3.setText(selected2);
                Style s = styleCrudService.getByPropertyName("style_name", jTextField3.getText());
                jTextField2.setText(Double.toString(s.getPrice()));
            }
        }
    });
}

From source file:io.github.jeremgamer.editor.panels.Actions.java

public Actions(final JFrame frame, final ActionPanel ap) {
    this.frame = frame;

    this.setBorder(BorderFactory.createTitledBorder(""));
    JButton add = null;//ww w  .  j a va  2  s.c  om
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog(null, "Nommez l'action :", "Crer une action",
                        JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new ActionSave(name);
                    OtherPanel.updateLists();
                    ButtonPanel.updateLists();
                    ActionPanel.updateLists();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (actionList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/actions/"
                            + actionList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog(null,
                            "tes-vous sr de vouloir supprimer cette action?", "Avertissement",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        if (actionList.getSelectedValue().equals(ap.getFileName())) {
                            ap.setFileName("");
                        }
                        ap.hide();
                        file.delete();
                        data.remove(actionList.getSelectedIndex());
                        OtherPanel.updateLists();
                        ButtonPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    updateList();
    actionList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    ap.show();
                    ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            ap.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            ap.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        ap.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    ap.show();
                    ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            ap.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            ap.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        ap.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(actionList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);
    OtherPanel.updateLists();
}

From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java

private void pickListUpAction(final JList list) {
    final DefaultListModel selectedListModel = (DefaultListModel) list.getModel();
    final int selectedIndex = list.getSelectedIndex();
    Object element;//from   w w w.  ja v  a2 s  . c  om
    if (selectedIndex > 0) {
        element = list.getSelectedValue();
        selectedListModel.remove(selectedIndex);
        selectedListModel.add(selectedIndex - 1, element);
    }
}