List of usage examples for javax.swing DefaultListModel addElement
public void addElement(E element)
From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java
public static DefaultListModel<String> listDemoMachines(String demoMachineRootFolder) { DefaultListModel<String> demoMachines = new DefaultListModel<String>(); File folder = new File(demoMachineRootFolder + File.separator + "demos"); if (folder.exists()) { File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isDirectory()) { demoMachines.addElement(listOfFiles[i].getName()); }/*from www . j a va 2 s. c o m*/ } } return demoMachines; }
From source file:Main.java
public Main() { DefaultListModel<String> model = new DefaultListModel<>(); model.addElement("one"); model.addElement("two"); model.addElement("three"); model.addElement("four"); model.addElement("five"); model.addElement("six"); model.addElement("seven"); model.addElement("eight"); model.addElement("nine"); model.addElement("ten"); JList<String> list = new JList(model) { public String getToolTipText(MouseEvent e) { int row = locationToIndex(e.getPoint()); Object o = getModel().getElementAt(row); return o.toString(); }// w w w .j a v a 2s .c om public Point getToolTipLocation(MouseEvent e) { int row = locationToIndex(e.getPoint()); Rectangle r = getCellBounds(row, row); return new Point(r.width, r.y); } }; JScrollPane scrollPane = new JScrollPane(list); getContentPane().add(scrollPane); }
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); }/*from w w w . ja va2s .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:fr.duminy.jbackup.swing.SourceListTypeMapper.java
@Override public void setValue(@Nonnull ListPanel<Source, JList<Source>> listPanel, @Nullable List o) { DefaultListModel<Source> model = getModel(listPanel); model.clear();//from w w w. ja v a 2 s.c om if (o != null) { for (Source source : (List<Source>) o) { model.addElement(source); } } }
From source file:be.fedict.eid.tsl.tool.SignSelectCertificatePanel.java
@Override public Component getComponent() { LOG.debug("get component"); if (null == this.pkcs11Token) { String pkcs11Library = this.pkcs11Panel.getPkcs11Library(); int slotIdx = this.pkcs11Panel.getSlotIdx(); LOG.debug("PKCS#11 library: " + pkcs11Library); try {//w ww. j av a 2 s . co m this.pkcs11Token = new Pkcs11Token(pkcs11Library, slotIdx); List<String> aliases = this.pkcs11Token.getAliases(); DefaultListModel listModel = (DefaultListModel) this.certificateList.getModel(); for (String alias : aliases) { listModel.addElement(alias); } } catch (Exception e) { LOG.debug("error: " + e.getMessage(), e); } } return this.component; }
From source file:BasicDnD.java
public BasicDnD() { super(new BorderLayout()); JPanel leftPanel = createVerticalBoxPanel(); JPanel rightPanel = createVerticalBoxPanel(); //Create a table model. DefaultTableModel tm = new DefaultTableModel(); tm.addColumn("Column 0"); tm.addColumn("Column 1"); tm.addColumn("Column 2"); tm.addColumn("Column 3"); tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" }); tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" }); tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" }); tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" }); //LEFT COLUMN //Use the table model to create a table. table = new JTable(tm); leftPanel.add(createPanelForComponent(table, "JTable")); //Create a color chooser. colorChooser = new JColorChooser(); leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser")); //RIGHT COLUMN //Create a textfield. textField = new JTextField(30); textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast"); rightPanel.add(createPanelForComponent(textField, "JTextField")); //Create a scrolled text area. textArea = new JTextArea(5, 30); textArea.setText("Favorite shows:\nBuffy, Alias, Angel"); JScrollPane scrollPane = new JScrollPane(textArea); rightPanel.add(createPanelForComponent(scrollPane, "JTextArea")); //Create a list model and a list. DefaultListModel listModel = new DefaultListModel(); listModel.addElement("Martha Washington"); listModel.addElement("Abigail Adams"); listModel.addElement("Martha Randolph"); listModel.addElement("Dolley Madison"); listModel.addElement("Elizabeth Monroe"); listModel.addElement("Louisa Adams"); listModel.addElement("Emily Donelson"); list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); JScrollPane listView = new JScrollPane(list); listView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(listView, "JList")); //Create a tree. DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia"); DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon"); rootNode.add(sharon);//from ww w . jav a2 s . com DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya"); sharon.add(maya); DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya"); sharon.add(anya); sharon.add(new DefaultMutableTreeNode("Bongo")); maya.add(new DefaultMutableTreeNode("Muffin")); anya.add(new DefaultMutableTreeNode("Winky")); DefaultTreeModel model = new DefaultTreeModel(rootNode); tree = new JTree(model); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JScrollPane treeView = new JScrollPane(tree); treeView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(treeView, "JTree")); //Create the toggle button. toggleDnD = new JCheckBox("Turn on Drag and Drop"); toggleDnD.setActionCommand("toggleDnD"); toggleDnD.addActionListener(this); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); splitPane.setOneTouchExpandable(true); add(splitPane, BorderLayout.CENTER); add(toggleDnD, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:interfaceTisseoWS.ST4.java
public final void init() throws ParseException, IOException, URISyntaxException { RequestJCDecaux r = new RequestJCDecaux(); JSONParser parser = new JSONParser(); r.setPathURIB("/vls/v1/stations"); Object obj = parser.parse(r.request()); JSONArray array = (JSONArray) obj;/*from ww w .ja v a 2 s .c o m*/ int nbStations = array.size(); DefaultListModel lm = new DefaultListModel(); for (int i = 0; i < nbStations; i++) { stations.add(new Station((JSONObject) array.get(i))); lm.addElement(stations.get(i).getName()); } listeStations.setModel(lm); }
From source file:com.iisigroup.ris.WebFileScanUtilBrowserUI.java
public WebFileScanUtilBrowserUI sourceFileList(List<PageInfo> list) { if (list == null || list.isEmpty()) { return this; }// ww w . jav a2 s .c om List<MFile> lll = new ArrayList<MFile>(); for (PageInfo pageinfo : list) { if (pageinfo.getOrignWebFile() != null) { lll.add(new MFile(pageinfo.getOrignWebFile(), "WEB")); } if (pageinfo.getSourceFile() != null) { lll.add(new MFile(pageinfo.getSourceFile(), "SRC")); } } DefaultListModel model = new DefaultListModel(); for (MFile f : lll) { model.addElement(f); } openFileList.setModel(model); return this; }
From source file:interfaceTisseoWS.ST1.java
private void listeLignesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_listeLignesItemStateChanged DefaultListModel lm = new DefaultListModel(); for (int i = 0; i < departs.get(listeLignes.getSelectedIndex() - 1).nbDeparts(); i++) {//remplissage de la lsite avec les prochains dparts lm.addElement(departs.get(listeLignes.getSelectedIndex() - 1).toString(i)); }/* w ww.j ava2 s . c o m*/ horaires.setModel(lm); }
From source file:DropDemo.java
private JPanel createList() { DefaultListModel listModel = new DefaultListModel(); for (int i = 0; i < 10; i++) { listModel.addElement("List Item " + i); }/*from w ww . jav a2 s .c om*/ list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); JScrollPane scrollPane = new JScrollPane(list); scrollPane.setPreferredSize(new Dimension(400, 100)); list.setDragEnabled(true); list.setTransferHandler(new ListTransferHandler()); dropCombo = new JComboBox(new String[] { "USE_SELECTION", "ON", "INSERT", "ON_OR_INSERT" }); dropCombo.addActionListener(this); JPanel dropPanel = new JPanel(); dropPanel.add(new JLabel("List Drop Mode:")); dropPanel.add(dropCombo); JPanel panel = new JPanel(new BorderLayout()); panel.add(scrollPane, BorderLayout.CENTER); panel.add(dropPanel, BorderLayout.SOUTH); panel.setBorder(BorderFactory.createTitledBorder("List")); return panel; }