private JComponent createXPathResultPanel() { xpathResults.addElement("No XPath results yet, run an XPath Query first."); xpathResultList.setBorder(BorderFactory.createLineBorder(Color.black)); xpathResultList.setFixedCellWidth(300); xpathResultList.setCellRenderer(new ASTListCellRenderer()); xpathResultList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); xpathResultList.getSelectionModel().addListSelectionListener(new ASTSelectionListener()); JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().setView(xpathResultList); return scrollPane; }
contentPanel.add(buttonsPanel, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); JButton addButton = new JButton("Add"); buttonsPanel.add(addButton); addButton.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent event) { FileDialog dialog = new FileDialog(editor, "Open Image", FileDialog.LOAD); JButton defaultButton = new JButton("Default"); buttonsPanel.add(defaultButton); defaultButton.addActionListener(new ActionListener() { contentPanel.add(imagesPanel, new GridBagConstraints(2, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); imageListModel = new DefaultListModel<String>(); imageList = new JList<String>(imageListModel); imageList.setFixedCellWidth(250); imageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); imagesPanel.add(imageList, new GridBagConstraints(0, 0, 1, 3, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
private void refreshQuickOpenPanel(JList<QuickOpenAction> listPanel, List<File> fileList) { DefaultListModel<QuickOpenAction> model = (DefaultListModel<QuickOpenAction>) listPanel.getModel(); model.clear(); for (File file : fileList) { QuickOpenAction action = new QuickOpenAction(file); model.addElement(action); listPanel.clearSelection(); } }
public void updateImageList (Array<String> imagePaths) { if (imagePaths != null && imagePaths.size > 0) { imagesPanel.setVisible(true); imageListModel.removeAllElements(); for (String imagePath : imagePaths) { imageListModel.addElement(new File(imagePath).getName()); } } else { imagesPanel.setVisible(false); } revalidate(); } }
DefaultListModel model = new DefaultListModel(); model.addElement("one"); model.addElement("two"); JList list = new JList(model);
import java.awt.*; import javax.swing.*; public class Temp extends JPanel{ public Temp(){ DefaultListModel list1items = new DefaultListModel(); list1items.addElement("-"); for(int i = 0; i < 200; i++) list1items.addElement("Item " + i); JList list1 = new JList(list1items); list1.setSelectionMode (ListSelectionModel.SINGLE_SELECTION); JScrollPane list1scr = new JScrollPane(list1); list1.setVisibleRowCount(8); add (list1scr); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new Temp()); frame.pack(); frame.setVisible(true); } }
public static void main(String[] args) { DefaultListModel m = new DefaultListModel(); for (int i = 0; i < 5000; i++) { m.addElement("X" + i); } CheckList list = new CheckList(new JList(m)); JFrame f = new JFrame(); f.getContentPane().setLayout(new BorderLayout()); f.getContentPane().add(new JScrollPane(list)); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
JList imageList = new JList(createModel()); imageList.setCellRenderer(new ImageCellRenderer()); imageList.setLayoutOrientation(JList.HORIZONTAL_WRAP); DefaultListModel model = new DefaultListModel(); model.addElement(new ColorIcon(Color.RED)); model.addElement(new ColorIcon(Color.GREEN)); model.addElement(new ColorIcon(Color.BLACK)); model.addElement(new ColorIcon(Color.BLUE)); model.addElement(new ColorIcon(Color.MAGENTA)); model.addElement(new ColorIcon(Color.PINK)); model.addElement(new ColorIcon(Color.YELLOW)); model.addElement(new ColorIcon(Color.ORANGE)); return model; if (model.indexOf(draggedImage) < dropIndex) { dropIndex--; model.removeElement(draggedImage); model.add(dropIndex, draggedImage); return true; } catch (Exception e) { setLayout(new BorderLayout()); Border emptyBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5); imageLabel.setBorder(emptyBorder); descriptionLabel.setBorder(emptyBorder); add(imageLabel, BorderLayout.CENTER);
private void setupHandlers() { ripButton.addActionListener(new RipButtonHandler()); ripTextfield.addActionListener(new RipButtonHandler()); ripTextfield.getDocument().addDocumentListener(new DocumentListener() { stopButton.addActionListener(event -> { if (ripper != null) { ripper.stop(); isRipping = false; stopButton.setEnabled(false); statusProgress.setValue(0); statusProgress.setVisible(false); if (entry.selected) { added++; queueListModel.addElement(entry.url); }); queueListModel.addListDataListener(new ListDataListener() { @Override public void intervalAdded(ListDataEvent arg0) {
logText = new JTextPane(); logText.setEditable(false); JScrollPane logTextScroll = new JScrollPane(logText); logTextScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); logPanel.setVisible(false); logPanel.setPreferredSize(new Dimension(300, 250)); JScrollPane historyTableScrollPane = new JScrollPane(historyTable); queuePanel.setVisible(false); queuePanel.setPreferredSize(new Dimension(300, 250)); queueListModel = new DefaultListModel(); JList queueList = new JList(queueListModel); queueList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); queueList.addMouseListener(new QueueMenuMouseListener()); JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); for (String item : Utils.getConfigList("queue")) { queueListModel.addElement(item); gbc.gridy = 0; pane.add(ripPanel, gbc); gbc.gridy = 1; pane.add(statusPanel, gbc); gbc.gridy = 2; pane.add(progressPanel, gbc);
DefaultListModel<Thumbnail> m = new DefaultListModel<>(); for(String s: Arrays.asList("error","information","question","warning")) { m.addElement(new Thumbnail(s)); JList<Thumbnail> list = new JList<>(m); list.getSelectionModel().setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setTransferHandler(new ListItemTransferHandler()); list.setDropMode(DropMode.INSERT); p.add(icon); p.add(label, BorderLayout.SOUTH); return new JScrollPane(list); int max = listModel.getSize(); if(index<0 || index>max) { index = max; for(int i=0; i<values.length; i++) { int idx = index++; listModel.add(idx, values[i]); model.remove(indices[i]);
JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); final JButton setButton = new JButton("Select"); setButton.setActionCommand("Select"); setButton.addActionListener(this); getRootPane().setDefaultButton(setButton); model = new DefaultListModel(); list = new JList(model); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setLayoutOrientation(JList.VERTICAL); list.setVisibleRowCount(-1); list.addMouseListener( JScrollPane listScroller = new JScrollPane(list); listScroller.setPreferredSize(new Dimension(400, 280)); JPanel listPane = new JPanel(); listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); contentPane.add(listPane, BorderLayout.CENTER); contentPane.add(buttonPane, BorderLayout.PAGE_END);
final JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); getContentPane().setLayout(new BorderLayout()); getContentPane().add(mainPanel, BorderLayout.CENTER); mainPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); DefaultListModel model = new DefaultListModel(); for (Class c : classes) { model.addElement(c); mainPanel.add(new JScrollPane(list), BorderLayout.CENTER); mainPanel.add(buttonPanel, BorderLayout.PAGE_END); final JButton okButton = new JButton("Ok"); okButton.setMnemonic('O'); buttonPanel.add(okButton); getRootPane().setDefaultButton(okButton); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { startApp(selectedClass);
JFrame mainFrame = new JFrame("MVC example"); mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); mainFrame.setSize(640, 300); mainFrame.setLocationRelativeTo(null); DefaultListModel searchResultListModel = new DefaultListModel(); DefaultListSelectionModel searchResultSelectionModel = new DefaultListSelectionModel(); searchResultSelectionModel searchInputPanel.add(searchButton, BorderLayout.EAST); JList searchResultList = new JList(); searchResultList.setModel(searchResultListModel); searchResultList.setSelectionModel(searchResultSelectionModel); JButton showPersonDetailsButton = new JButton(personDetailsAction); selectionOptionsPanel.add(showPersonDetailsButton); contentPane.add(searchInputPanel, BorderLayout.NORTH); contentPane.add(searchResultPanel, BorderLayout.CENTER); contentPane.add(selectionOptionsPanel, BorderLayout.SOUTH); mainFrame.setVisible(true);
private DefaultListModel listModel = new DefaultListModel(); private DropTarget dropTarget; initComponents(); dropTarget = new DropTarget(list, this); list.setModel(listModel); list.setDragEnabled(true); list.setTransferHandler(new FileTransferHandler()); jScrollPane1 = new javax.swing.JScrollPane(); list = new javax.swing.JList(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(new java.awt.GridBagLayout()); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; getContentPane().add(jLabel1, gridBagConstraints); jScrollPane1.setViewportView(list); getContentPane().add(jScrollPane1, gridBagConstraints); pack(); DataFlavor.javaFileListFlavor); for (File file : files) { listModel.addElement(file);
public ClassListItem(Class<? extends T1> clz) { this.clz = clz; }
listModel = new DefaultListModel(); listModel.addElement(feedbackSettings.getFeedbackSettingsName()); feedbackSettingsList = new JList(listModel); //data has type Object[] feedbackSettingsList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); feedbackSettingsList.setLayoutOrientation(JList.VERTICAL); feedbackSettingsList.setVisibleRowCount(-1); feedbackSettingsList.setSelectedIndex(0); JScrollPane feedbackSettingsScroller = new JScrollPane(feedbackSettingsList); feedbackSettingsScroller.setMaximumSize(new Dimension(windowWidth, 180)); JButton button = new JButton("select"); button.addActionListener(new ActionListener() button.setHorizontalAlignment(JButton.LEFT);
JFrame f = new JFrame("MultiLineList"); f.setResizable(true); f.setVisible(true); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().setLayout(new BorderLayout()); final DefaultListModel model = new DefaultListModel(); model.addElement("This is a short text"); model.addElement("This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. "); model.addElement("This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. This is an even longer text. "); final JList list = new JList(model); list.setCellRenderer(new MyCellRenderer()); f.add(list); f.pack(); IconPanel.add(l, BorderLayout.NORTH); p.add(IconPanel, BorderLayout.WEST);
pane.add(rightPanel, BorderLayout.LINE_END); pathStates = new JList<State>(); JScrollPane stScrollPane = new JScrollPane(pathStates); stScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); rightPanelTabs.addTab("path states", stScrollPane); pathStates.addListSelectionListener(new ListSelectionListener(){ @Override public void valueChanged(ListSelectionEvent e) { metadataList = new JList<String>(); metadataModel = new DefaultListModel<String>(); metadataList.setModel(metadataModel); JScrollPane mdScrollPane = new JScrollPane(metadataList); mdScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); rightPanelTabs.addTab("metadata", mdScrollPane); annotationMatchesModel = new DefaultListModel<GraphBuilderAnnotation>(); annotationMatches.setModel(annotationMatchesModel); JScrollPane amScrollPane = new JScrollPane(annotationMatches);