Example usage for javax.swing ListSelectionModel SINGLE_SELECTION

List of usage examples for javax.swing ListSelectionModel SINGLE_SELECTION

Introduction

In this page you can find the example usage for javax.swing ListSelectionModel SINGLE_SELECTION.

Prototype

int SINGLE_SELECTION

To view the source code for javax.swing ListSelectionModel SINGLE_SELECTION.

Click Source Link

Document

A value for the selectionMode property: select one list index at a time.

Usage

From source file:SiteFrame.java

public SiteFrame(String name, SiteManager sm) {
    super("Site: " + name, true, true, true);
    parent = sm;//from  www. j  ava2s  . co m
    setBounds(50, 50, 250, 100);

    nameList = new JList(pages);
    nameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    nameList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent lse) {
            // We know this is the list, so pop up the page.
            if (!lse.getValueIsAdjusting()) {
                parent.addPageFrame((String) nameList.getSelectedValue());
            }
        }
    });
    Container contentPane = getContentPane();
    contentPane.add(nameList, BorderLayout.CENTER);
}

From source file:brainflow.core.ImageBrowser.java

private void initSourceView() {
    sourceView = new JList();
    final DefaultListModel model = new DefaultListModel();
    for (IImageSource source : sourceList.sourceList) {
        model.addElement(source);/*  w ww.jav a 2 s.  c o m*/
    }

    sourceView.setModel(model);
    sourceView.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    ButtonPanel panel = new ButtonPanel(SwingConstants.CENTER);

    JButton nextButton = new JButton("Next");
    ImageIcon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/control_play_blue.png"));
    nextButton.setIcon(icon);

    JButton prevButton = new JButton("Previous");
    icon = new ImageIcon(getClass().getClassLoader().getResource("icons/control_rev_blue.png"));
    prevButton.setIcon(icon);
    panel.addButton(prevButton);
    panel.addButton(nextButton);
    panel.setSizeConstraint(ButtonPanel.SAME_SIZE);

    JPanel container = new JPanel(new BorderLayout());
    container.setBorder(new TitledBorder("Image List"));
    container.add(new JScrollPane(sourceView), BorderLayout.CENTER);
    container.add(panel, BorderLayout.SOUTH);
    add(container, BorderLayout.WEST);

    nextButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int index = sourceView.getSelectedIndex();
            if (index == (sourceList.size() - 1)) {
                index = 0;
            } else {
                index++;
            }

            updateView(index);

        }
    });

    sourceView.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            int index = sourceView.getSelectedIndex();
            if (currentModel.getSelectedLayer().getDataSource() != sourceView.getSelectedValue()) {
                System.out.println("updating view");
                updateView(index);
            } else {
                System.out.println("not updating view ");
            }

        }
    });
}

From source file:Main.java

/**
 * Setups the given table for usage as row-header. This method setups the background color to
 * the same one than the column headers.
 *
 * {@note In a previous version, we were assigning to the row headers the same cell renderer than
 *        the one created by <cite>Swing</cite> for the column headers. But it produced strange
 *        effects when the L&F uses a vertical grandiant instead than a uniform color.}
 *
 * @param  table The table to setup as row headers.
 * @return The renderer which has been assigned to the table.
 *///from   w  w  w  .j  a v  a  2s.co  m
public static TableCellRenderer setupAsRowHeader(final JTable table) {
    final JTableHeader header = table.getTableHeader();
    Color background = header.getBackground();
    Color foreground = header.getForeground();
    if (background == null || background.equals(table.getBackground())) {
        if (!SystemColor.control.equals(background)) {
            background = SystemColor.control;
            foreground = SystemColor.controlText;
        } else {
            final Locale locale = table.getLocale();
            background = UIManager.getColor("Label.background", locale);
            foreground = UIManager.getColor("Label.foreground", locale);
        }
    }
    final DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setBackground(background);
    renderer.setForeground(foreground);
    renderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT);
    final TableColumn column = table.getColumnModel().getColumn(0);
    column.setCellRenderer(renderer);
    column.setPreferredWidth(60);
    table.setPreferredScrollableViewportSize(table.getPreferredSize());
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setCellSelectionEnabled(false);
    return renderer;
}

From source file:Main.java

public Main() {

    for (int i = 0; i < 15; i++) {
        ((DefaultListModel<String>) sourceList.getModel()).add(i, "A " + i);
        ((DefaultListModel<String>) destList.getModel()).add(i, "B " + i);
    }//from  ww w . j av a2s.c  om
    Box nameBox = Box.createHorizontalBox();
    nameBox.add(new JLabel("New:"));
    nameBox.add(newTextField);

    Box sourceBox = Box.createVerticalBox();
    sourceBox.add(new JLabel("Source"));
    sourceBox.add(new JScrollPane(sourceList));

    Box destBox = Box.createVerticalBox();
    destBox.add(new JLabel("Destination"));
    destBox.add(new JScrollPane(destList));

    Box listBox = Box.createHorizontalBox();
    listBox.add(sourceBox);
    listBox.add(destBox);

    Box allBox = Box.createVerticalBox();
    allBox.add(nameBox);
    allBox.add(listBox);

    this.getContentPane().add(allBox, BorderLayout.CENTER);

    sourceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    destList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    newTextField.setDragEnabled(true);
    sourceList.setDragEnabled(true);
    destList.setDragEnabled(true);

    sourceList.setDropMode(DropMode.INSERT);
    destList.setDropMode(DropMode.INSERT);

    sourceList.setTransferHandler(new ListTransferHandler());
    destList.setTransferHandler(new ListTransferHandler());
}

From source file:com.sec.ose.osi.ui.frm.main.identification.stringmatch.table.JTableInfoForSMFolder.java

public JTableInfoForSMFolder() {
    tableModelFolder = new TableModelForSMFolder();

    this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.setModel(tableModelFolder);
    this.setDefaultRenderer(this.getColumnClass(0), new IdentificationTableRendererForSMFolder());
    this.setPreferredScrollableViewportSize(new Dimension(300, 200));
}

From source file:com.sec.ose.osi.ui.frm.main.identification.stringmatch.table.JTableInfoForSMFile.java

public JTableInfoForSMFile() {
    tableModelFile = new TableModelForSMFile();

    this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.setModel(tableModelFile);
    this.setDefaultRenderer(this.getColumnClass(0), new IdentificationTableRendererForSMFile());
    this.setPreferredScrollableViewportSize(new Dimension(300, 200));
}

From source file:com.sec.ose.osi.ui.frm.main.identification.stringmatch.table.JTableInfoForSMMultipleFile.java

public JTableInfoForSMMultipleFile() {
    tableModelMultipleFile = new TableModelForSMMultipleFile();

    this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.setModel(tableModelMultipleFile);
    this.setDefaultRenderer(this.getColumnClass(0), new IdentificationTableRendererForMultipleFile());
    this.setPreferredScrollableViewportSize(new Dimension(300, 200));
}

From source file:LongListTest.java

public LongListFrame() {
    setTitle("LongListTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    wordList = new JList(new WordListModel(3));
    wordList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    wordList.setPrototypeCellValue("www");
    JScrollPane scrollPane = new JScrollPane(wordList);

    JPanel p = new JPanel();
    p.add(scrollPane);//w ww.  j  av a2  s.  co  m
    wordList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            StringBuilder word = (StringBuilder) wordList.getSelectedValue();
            setSubject(word.toString());
        }

    });

    Container contentPane = getContentPane();
    contentPane.add(p, BorderLayout.NORTH);
    label = new JLabel(prefix + suffix);
    contentPane.add(label, BorderLayout.CENTER);
    setSubject("fox");
}

From source file:de.dakror.virtualhub.client.dialog.ChooseCatalogDialog.java

public static void show(ClientFrame frame, final JSONArray data) {
    final JDialog dialog = new JDialog(frame, "Katalog whlen", true);
    dialog.setSize(400, 300);//w  ww . j ava 2s. c o m
    dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            Client.currentClient.disconnect();
            System.exit(0);
        }
    });

    JPanel contentPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    dialog.setContentPane(contentPane);
    DefaultListModel dlm = new DefaultListModel();
    for (int i = 0; i < data.length(); i++) {
        try {
            dlm.addElement(data.getJSONObject(i).getString("name"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    final JList catalogs = new JList(dlm);
    catalogs.setDragEnabled(false);
    catalogs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JScrollPane jsp = new JScrollPane(catalogs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jsp.setPreferredSize(new Dimension(396, 200));
    contentPane.add(jsp);

    JPanel mods = new JPanel(new GridLayout(1, 2));
    mods.setPreferredSize(new Dimension(50, 22));
    mods.add(new JButton(new AbstractAction("+") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            String name = JOptionPane.showInputDialog(dialog,
                    "Bitte geben Sie den Namen des neuen Katalogs ein.", "Katalog hinzufgen",
                    JOptionPane.PLAIN_MESSAGE);
            if (name != null && name.length() > 0) {
                DefaultListModel dlm = (DefaultListModel) catalogs.getModel();
                for (int i = 0; i < dlm.getSize(); i++) {
                    if (dlm.get(i).toString().equals(name)) {
                        JOptionPane.showMessageDialog(dialog,
                                "Es existert bereits ein Katalog mit diesem Namen!",
                                "Katalog bereits vorhanden!", JOptionPane.ERROR_MESSAGE);
                        actionPerformed(e);
                        return;
                    }
                }

                try {
                    dlm.addElement(name);
                    JSONObject o = new JSONObject();
                    o.put("name", name);
                    o.put("sources", new JSONArray());
                    o.put("tags", new JSONArray());
                    data.put(o);
                    Client.currentClient.sendPacket(new Packet0Catalogs(data));
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    }));
    mods.add(new JButton(new AbstractAction("-") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (catalogs.getSelectedIndex() != -1) {
                if (JOptionPane.showConfirmDialog(dialog,
                        "Sind Sie sicher, dass Sie diesen\r\nKatalog unwiderruflich lschen wollen?",
                        "Katalog lschen", JOptionPane.YES_NO_CANCEL_OPTION,
                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                    DefaultListModel dlm = (DefaultListModel) catalogs.getModel();
                    data.remove(catalogs.getSelectedIndex());
                    dlm.remove(catalogs.getSelectedIndex());
                    try {
                        Client.currentClient.sendPacket(new Packet0Catalogs(data));
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    }));

    contentPane.add(mods);

    JLabel l = new JLabel("");
    l.setPreferredSize(new Dimension(396, 14));
    contentPane.add(l);

    JSeparator sep = new JSeparator(JSeparator.HORIZONTAL);
    sep.setPreferredSize(new Dimension(396, 10));
    contentPane.add(sep);

    JPanel buttons = new JPanel(new GridLayout(1, 2));
    buttons.setPreferredSize(new Dimension(396, 22));
    buttons.add(new JButton(new AbstractAction("Abbrechen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            Client.currentClient.disconnect();
            System.exit(0);
        }
    }));
    buttons.add(new JButton(new AbstractAction("Katalog whlen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (catalogs.getSelectedIndex() != -1) {
                try {
                    Client.currentClient
                            .setCatalog(new Catalog(data.getJSONObject(catalogs.getSelectedIndex())));
                    Client.currentClient.frame.setTitle("- " + Client.currentClient.getCatalog().getName());
                    dialog.dispose();
                } catch (JSONException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }));

    dialog.add(buttons);

    dialog.setLocationRelativeTo(frame);
    dialog.setResizable(false);
    dialog.setVisible(true);
}

From source file:Main.java

public MyPanel() {
    add(new JScrollPane(selectionList));
    selectionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}