Example usage for javax.swing JList JList

List of usage examples for javax.swing JList JList

Introduction

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

Prototype

public JList(final Vector<? extends E> listData) 

Source Link

Document

Constructs a JList that displays the elements in the specified Vector.

Usage

From source file:com.eviware.soapui.support.log.JLogList.java

public JLogList(String title) {
    super(new BorderLayout());
    this.title = title;

    model = new LogListModel();
    logList = new JList(model);
    logList.setToolTipText(title);//from   w  w w  . ja  v a 2 s . co  m
    logList.setCellRenderer(new LogAreaCellRenderer());
    logList.setPrototypeCellValue("Testing 123");
    logList.setFixedCellWidth(-1);

    JPopupMenu listPopup = new JPopupMenu();
    listPopup.add(new ClearAction());
    enableAction = new EnableAction();
    enableMenuItem = new JCheckBoxMenuItem(enableAction);
    enableMenuItem.setSelected(true);
    listPopup.add(enableMenuItem);
    listPopup.addSeparator();
    listPopup.add(new CopyAction());
    listPopup.add(new SetMaxRowsAction());
    listPopup.addSeparator();
    listPopup.add(new ExportToFileAction());

    logList.setComponentPopupMenu(listPopup);

    setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    JScrollPane scrollPane = new JScrollPane(logList);
    UISupport.addPreviewCorner(scrollPane, true);
    add(scrollPane, BorderLayout.CENTER);

    requestAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(requestAttributes, Color.BLUE);

    responseAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(responseAttributes, Color.GREEN);

    try {
        maxRows = Long.parseLong(SoapUI.getSettings().getString("JLogList#" + title, "1000"));
    } catch (NumberFormatException e) {
    }
}

From source file:joshua.ui.hypergraph_visualizer.HyperGraphViewer.java

public HyperGraphViewer(JungHyperGraph g, SymbolTable vocab) {
    super(new StaticLayout<Vertex, Edge>(g, new HyperGraphTransformer(g)));
    this.vocab = vocab;
    this.graph = g;
    this.edgeList = new JList(new DefaultListModel());
    this.edgeList.setCellRenderer(new HyperEdgeListCellRenderer(vocab));
    this.edgeList.addListSelectionListener(new HyperEdgeListSelectionListener(this));
    //      super(new DAGLayout<Vertex,Edge>(g));
    //      DelegateTree<Vertex,Edge> gtree = new DelegateTree<Vertex,Edge>(g);
    //      gtree.setRoot(g.getRoot());
    //      setGraphLayout(new TreeLayout<Vertex,Edge>(gtree));
    //      setGraphLayout(new StaticLayout<Vertex,Edge>(g, new HyperGraphTransformer(g)));
    getRenderContext().setVertexLabelTransformer(toStringTransformer());
    //      getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Vertex>());
    setVertexToolTipTransformer(toolTipTransformer());

    DefaultModalGraphMouse<Vertex, Edge> graphMouse = new DefaultModalGraphMouse<Vertex, Edge>();
    graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);
    this.setPickedVertexState(new HyperGraphPickedState(this));
    setGraphMouse(graphMouse);//from  w ww.  jav  a  2  s  .  c o m
    addKeyListener(graphMouse.getModeKeyListener());

    getRenderContext().setVertexFillPaintTransformer(vertexPainter());
    //   getRenderContext().setEdgeStrokeTransformer(es);
    getRenderContext().setVertexShapeTransformer(ns);
    //   getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
}

From source file:components.SharedModelDemo.java

public SharedModelDemo() {
    super(new BorderLayout());

    Vector data = new Vector(7);
    String[] columnNames = { "French", "Spanish", "Italian" };
    String[] oneData = { "un", "uno", "uno" };
    String[] twoData = { "deux", "dos", "due" };
    String[] threeData = { "trois", "tres", "tre" };
    String[] fourData = { "quatre", "cuatro", "quattro" };
    String[] fiveData = { "cinq", "cinco", "cinque" };
    String[] sixData = { "six", "seis", "sei" };
    String[] sevenData = { "sept", "siete", "sette" };

    //Build the model.
    SharedDataModel dataModel = new SharedDataModel(columnNames);
    dataModel.addElement(oneData);//from   w ww.jav  a2 s  . c o m
    dataModel.addElement(twoData);
    dataModel.addElement(threeData);
    dataModel.addElement(fourData);
    dataModel.addElement(fiveData);
    dataModel.addElement(sixData);
    dataModel.addElement(sevenData);

    list = new JList(dataModel);
    list.setCellRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList l, Object value, int i, boolean s, boolean f) {
            String[] array = (String[]) value;
            return super.getListCellRendererComponent(l, array[0], i, s, f);
        }
    });

    listSelectionModel = list.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    JScrollPane listPane = new JScrollPane(list);

    table = new JTable(dataModel);
    table.setSelectionModel(listSelectionModel);
    JScrollPane tablePane = new JScrollPane(table);

    //Build control area (use default FlowLayout).
    JPanel controlPane = new JPanel();
    String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" };

    final JComboBox comboBox = new JComboBox(modes);
    comboBox.setSelectedIndex(2);
    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String newMode = (String) comboBox.getSelectedItem();
            if (newMode.equals("SINGLE_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            } else {
                listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            }
            output.append("----------" + "Mode: " + newMode + "----------" + newline);
        }
    });
    controlPane.add(new JLabel("Selection mode:"));
    controlPane.add(comboBox);

    //Build output area.
    output = new JTextArea(10, 40);
    output.setEditable(false);
    JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    //Do the layout.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(splitPane, BorderLayout.CENTER);

    JPanel topHalf = new JPanel();
    topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.X_AXIS));
    JPanel listContainer = new JPanel(new GridLayout(1, 1));
    listContainer.setBorder(BorderFactory.createTitledBorder("List"));
    listContainer.add(listPane);
    JPanel tableContainer = new JPanel(new GridLayout(1, 1));
    tableContainer.setBorder(BorderFactory.createTitledBorder("Table"));
    tableContainer.add(tablePane);
    tablePane.setPreferredSize(new Dimension(300, 100));
    topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    topHalf.add(listContainer);
    topHalf.add(tableContainer);

    topHalf.setMinimumSize(new Dimension(400, 50));
    topHalf.setPreferredSize(new Dimension(400, 110));
    splitPane.add(topHalf);

    JPanel bottomHalf = new JPanel(new BorderLayout());
    bottomHalf.add(controlPane, BorderLayout.NORTH);
    bottomHalf.add(outputPane, BorderLayout.CENTER);
    //XXX: next line needed if bottomHalf is a scroll pane:
    //bottomHalf.setMinimumSize(new Dimension(400, 50));
    bottomHalf.setPreferredSize(new Dimension(450, 135));
    splitPane.add(bottomHalf);
}

From source file:ListDemo.java

public ListDemo() {
    super(new BorderLayout());

    listModel = new DefaultListModel();
    listModel.addElement("Debbie Scott");
    listModel.addElement("Scott Hommel");
    listModel.addElement("Sharon Zakhour");

    // Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);//  ww  w  .j a  va  2  s  .  c o  m
    list.addListSelectionListener(this);
    list.setVisibleRowCount(5);
    JScrollPane listScrollPane = new JScrollPane(list);

    JButton hireButton = new JButton(hireString);
    HireListener hireListener = new HireListener(hireButton);
    hireButton.setActionCommand(hireString);
    hireButton.addActionListener(hireListener);
    hireButton.setEnabled(false);

    fireButton = new JButton(fireString);
    fireButton.setActionCommand(fireString);
    fireButton.addActionListener(new FireListener());

    employeeName = new JTextField(10);
    employeeName.addActionListener(hireListener);
    employeeName.getDocument().addDocumentListener(hireListener);
    String name = listModel.getElementAt(list.getSelectedIndex()).toString();

    // Create a panel that uses BoxLayout.
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.add(fireButton);
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(new JSeparator(SwingConstants.VERTICAL));
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(employeeName);
    buttonPane.add(hireButton);
    buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    add(listScrollPane, BorderLayout.CENTER);
    add(buttonPane, BorderLayout.PAGE_END);
}

From source file:net.sf.jabref.gui.exporter.ExportToClipboardAction.java

@Override
public void run() {
    BasePanel panel = frame.getCurrentBasePanel();
    if (panel == null) {
        return;//from  w ww  . ja  v a 2s . c o  m
    }
    if (panel.getSelectedEntries().isEmpty()) {
        message = Localization.lang("This operation requires one or more entries to be selected.");
        getCallBack().update();
        return;
    }

    List<IExportFormat> exportFormats = new LinkedList<>(ExportFormats.getExportFormats().values());
    Collections.sort(exportFormats, (e1, e2) -> e1.getDisplayName().compareTo(e2.getDisplayName()));
    String[] exportFormatDisplayNames = new String[exportFormats.size()];
    for (int i = 0; i < exportFormats.size(); i++) {
        IExportFormat exportFormat = exportFormats.get(i);
        exportFormatDisplayNames[i] = exportFormat.getDisplayName();
    }

    JList<String> list = new JList<>(exportFormatDisplayNames);
    list.setBorder(BorderFactory.createEtchedBorder());
    list.setSelectionInterval(0, 0);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    int answer = JOptionPane.showOptionDialog(frame, list, Localization.lang("Select export format"),
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] {
                    Localization.lang("Export with selected format"), Localization.lang("Return to JabRef") },
            Localization.lang("Export with selected format"));
    if (answer == JOptionPane.NO_OPTION) {
        return;
    }

    IExportFormat format = exportFormats.get(list.getSelectedIndex());

    // Set the global variable for this database's file directory before exporting,
    // so formatters can resolve linked files correctly.
    // (This is an ugly hack!)
    Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectory();

    File tmp = null;
    try {
        // To simplify the exporter API we simply do a normal export to a temporary
        // file, and read the contents afterwards:
        tmp = File.createTempFile("jabrefCb", ".tmp");
        tmp.deleteOnExit();
        List<BibEntry> entries = panel.getSelectedEntries();

        // Write to file:
        format.performExport(panel.getBibDatabaseContext(), tmp.getPath(),
                panel.getBibDatabaseContext().getMetaData().getEncoding(), entries);
        // Read the file and put the contents on the clipboard:
        StringBuilder sb = new StringBuilder();
        try (Reader reader = new InputStreamReader(new FileInputStream(tmp),
                panel.getBibDatabaseContext().getMetaData().getEncoding())) {
            int s;
            while ((s = reader.read()) != -1) {
                sb.append((char) s);
            }
        }
        ClipboardOwner owner = (clipboard, content) -> {
            // Do nothing
        };
        RtfSelection rs = new RtfSelection(sb.toString());
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(rs, owner);
        message = Localization.lang("Entries exported to clipboard") + ": " + entries.size();

    } catch (Exception e) {
        LOGGER.error("Error exporting to clipboard", e); //To change body of catch statement use File | Settings | File Templates.
        message = Localization.lang("Error exporting to clipboard");
    } finally {
        // Clean up:
        if ((tmp != null) && !tmp.delete()) {
            LOGGER.info("Cannot delete temporary clipboard file");
        }
    }
}

From source file:DragListDemo.java

public DragListDemo() {
    arrayListHandler = new ArrayListTransferHandler();
    JList list1, list2;/* ww w  . java2s.c  o m*/

    DefaultListModel list1Model = new DefaultListModel();
    list1Model.addElement("0 (list 1)");
    list1Model.addElement("1 (list 1)");
    list1Model.addElement("2 (list 1)");
    list1Model.addElement("3 (list 1)");
    list1Model.addElement("4 (list 1)");
    list1Model.addElement("5 (list 1)");
    list1Model.addElement("6 (list 1)");
    list1 = new JList(list1Model);
    list1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list1.setTransferHandler(arrayListHandler);
    list1.setDragEnabled(true);
    JScrollPane list1View = new JScrollPane(list1);
    list1View.setPreferredSize(new Dimension(200, 100));
    JPanel panel1 = new JPanel();
    panel1.setLayout(new BorderLayout());
    panel1.add(list1View, BorderLayout.CENTER);
    panel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    DefaultListModel list2Model = new DefaultListModel();
    list2Model.addElement("0 (list 2)");
    list2Model.addElement("1 (list 2)");
    list2Model.addElement("2 (list 2)");
    list2Model.addElement("3 (list 2)");
    list2Model.addElement("4 (list 2)");
    list2Model.addElement("5 (list 2)");
    list2Model.addElement("6 (list 2)");
    list2 = new JList(list2Model);
    list2.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list2.setTransferHandler(arrayListHandler);
    list2.setDragEnabled(true);
    JScrollPane list2View = new JScrollPane(list2);
    list2View.setPreferredSize(new Dimension(200, 100));
    JPanel panel2 = new JPanel();
    panel2.setLayout(new BorderLayout());
    panel2.add(list2View, BorderLayout.CENTER);
    panel2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    setLayout(new BorderLayout());
    add(panel1, BorderLayout.LINE_START);
    add(panel2, BorderLayout.LINE_END);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:stockit.Manager.java

/**
 * Creates new form Trader/*from w  ww .j  av  a  2s  .  co  m*/
 */
public Manager() {
    initComponents();
    try {
        DefaultListModel demoList = new DefaultListModel();
        DBConnection dbcon = new DBConnection();
        dbcon.establishConnection();
        Statement stmt = dbcon.con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT tc.username"
                + "                       FROM trader as t, manager_account as mc,"
                + "                       trader_account as tc"
                + "                       WHERE t.Manager_SSN = mc.Manager_SSN AND tc.Trader_SSN = t.Trader_SSN"
                + "                       AND mc.username = \"" + username + "\"");
        while (rs.next()) {
            demoList.addElement(rs.getString("username"));

        }
        dbcon.con.close();
        listOfTraders = new JList(demoList);
        jScrollPane3.setViewportView(listOfTraders);
        //setUpTable();
    } catch (Exception ex) {
        Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:org.gumtree.vis.awt.AbstractPlotEditor.java

private JPanel createHelpPanel() {
    JPanel wrap = new JPanel(new GridLayout(1, 1));

    JPanel helpPanel = new JPanel(new GridLayout(1, 1));
    helpPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    //       helpPanel.setBorder(BorderFactory.createTitledBorder(
    //            BorderFactory.createEtchedBorder(), "Help Topics"));

    SpringLayout spring = new SpringLayout();
    JPanel inner = new JPanel(spring);
    inner.setBorder(BorderFactory.createEmptyBorder());

    final IHelpProvider provider = plot.getHelpProvider();
    final JList list = new JList(provider.getHelpMap().keySet().toArray());
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //      list.setBorder(BorderFactory.createEtchedBorder());
    JScrollPane listPane1 = new JScrollPane(list);
    inner.add(listPane1);/*from   www.  ja va  2s .  c om*/
    listPane1.setMaximumSize(new Dimension(140, 0));
    listPane1.setMinimumSize(new Dimension(70, 0));
    //      JPanel contentPanel = new JPanel(new GridLayout(2, 1));
    //      inner.add(list);
    final JTextField keyField = new JTextField();
    keyField.setMaximumSize(new Dimension(400, 20));
    keyField.setEditable(false);
    //      keyField.setMaximumSize();
    //      keyArea.setLineWrap(true);
    //      keyArea.setWrapStyleWord(true);
    //      keyArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(keyField);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    final JTextArea helpArea = new JTextArea();
    JScrollPane areaPane = new JScrollPane(helpArea);
    helpArea.setEditable(false);
    helpArea.setLineWrap(true);
    helpArea.setWrapStyleWord(true);
    //      helpArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(areaPane);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    //      inner.add(contentPanel);
    spring.putConstraint(SpringLayout.WEST, listPane1, 2, SpringLayout.WEST, inner);
    spring.putConstraint(SpringLayout.NORTH, listPane1, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.WEST, keyField, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, keyField, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.EAST, inner, 2, SpringLayout.EAST, keyField);
    spring.putConstraint(SpringLayout.WEST, areaPane, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, areaPane, 4, SpringLayout.SOUTH, keyField);
    spring.putConstraint(SpringLayout.EAST, areaPane, -2, SpringLayout.EAST, inner);
    spring.putConstraint(SpringLayout.SOUTH, inner, 2, SpringLayout.SOUTH, areaPane);
    spring.putConstraint(SpringLayout.SOUTH, listPane1, -2, SpringLayout.SOUTH, inner);

    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            Object[] selected = list.getSelectedValues();
            if (selected.length >= 0) {
                HelpObject help = provider.getHelpMap().get(selected[0]);
                if (help != null) {
                    keyField.setText(help.getKey());
                    helpArea.setText(help.getDiscription());
                }
            }
        }
    });

    helpPanel.add(inner, BorderLayout.NORTH);
    wrap.setName("Help");

    wrap.add(helpPanel, BorderLayout.NORTH);
    return wrap;
}

From source file:fr.duminy.jbackup.swing.ConfigurationManagerPanel.java

private static JList<BackupConfiguration> createList(ConfigurationManager manager) {
    //TODO enable sorting : JList list = new JList(new SortedListModel(new DefaultListModel(), COMPARATOR));
    JList<BackupConfiguration> list = new JList<>(new Model(manager));
    list.setCellRenderer(BackupConfigurationRenderer.INSTANCE);
    list.setName("configurations");
    return list;//  w  w  w. j av  a 2  s .  com
}

From source file:latexstudio.editor.DbxFileActions.java

/**
 * Shows a .tex files list from user's dropbox and opens the selected one
 *
 * @return List, that contatins user's .tex files from his dropbox; can be
 * empty//from   www .  j  av a2 s.  c om
 */
public void openFromDropbox(DropboxRevisionsTopComponent drtc, RevisionDisplayTopComponent revtc) {
    List<DbxEntryDto> dbxEntries = getDbxTexEntries(DbxUtil.getDbxClient());

    if (!dbxEntries.isEmpty()) {
        JList<DbxEntryDto> list = new JList(dbxEntries.toArray());
        list.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
        int option = JOptionPane.showConfirmDialog(null, list, "Open file from Dropbox",
                JOptionPane.OK_CANCEL_OPTION);

        if (option == JOptionPane.OK_OPTION && !list.isSelectionEmpty()) {
            DbxEntryDto entry = list.getSelectedValue();
            String localPath = ApplicationUtils.getAppDirectory() + File.separator + entry.getName();
            File outputFile = DbxUtil.downloadRemoteFile(entry, localPath);

            revtc.close();

            drtc.updateRevisionsList(entry.getPath());
            drtc.open();
            drtc.requestActive();

            String content = FileService.readFromFile(outputFile.getAbsolutePath());
            etc.setEditorContent(content);
            etc.setCurrentFile(outputFile);
            etc.setDbxState(new DbxState(entry.getPath(), entry.getRevision()));
            etc.setModified(false);
            etc.setPreviewDisplayed(false);
        }
    } else {
        JOptionPane.showMessageDialog(etc, "No .tex files found!", "Error", JOptionPane.ERROR_MESSAGE);
    }
}