List of usage examples for javax.swing DefaultListModel DefaultListModel
DefaultListModel
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 w ww . jav a 2 s .c o m } } return demoMachines; }
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);/*from w w w. j a v a 2 s . 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:CheckBoxList.java
public CheckBoxList() { super();//from ww w.j a v a 2s . c o m setModel(new DefaultListModel()); setCellRenderer(new CheckboxCellRenderer()); addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { int index = locationToIndex(e.getPoint()); if (index != -1) { Object obj = getModel().getElementAt(index); if (obj instanceof JCheckBox) { JCheckBox checkbox = (JCheckBox) obj; checkbox.setSelected(!checkbox.isSelected()); repaint(); } } } } ); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); }
From source file:iaws_desktop.VelibDispoDialogFrame.java
/** * Creates new form VelibDispoDialogFrame *///from w w w . j ava 2 s .c o m public VelibDispoDialogFrame(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); Document doc; JSONArray array; VelibWebRequest velibR = new VelibWebRequest("/vls/v1/stations"); velibR.addParameterGet("contract", "Toulouse"); try { array = (JSONArray) new JSONParser().parse(velibR.requestWithGet()); } catch (ParseException ex) { return; } listModel = new DefaultListModel<>(); JSONObject obj = null; for (int i = 0; i < array.size(); i++) { obj = (JSONObject) array.get(i); listModel.addElement(new VelibStation(obj.get("number").toString(), obj.get("name").toString())); } listVelib.setModel(listModel); }
From source file:hr.fer.zemris.vhdllab.applets.view.simulation.SimulationErrorsView.java
@Override protected JComponent createControl() { model = new DefaultListModel(); JList listContent = new JList(model); listContent.setFixedCellHeight(15);/*from w ww . j a v a 2s .co m*/ simulationManager.addListener(this); return new JScrollPane(listContent); }
From source file:finalproject.BloodGlucoseGUI.java
/** * Constructor/*from w ww . j a v a 2s . c o m*/ * Creates new form BloodGlucoseGUI */ // I would put most of it in initComponents if I could // edit that generated code. public BloodGlucoseGUI() { initComponents(); //jfc = new JFileChooser("Resources/Data"); // For "commercial" use //jfc = new JFileChooser("C:\\Program Files\\BGDataAnalysis\\Data"); jfc = new JFileChooser("C:\\BGDataAnalysis\\Data"); tabMod = new MyTableModel(); jTable2.setModel(tabMod); listMod = new DefaultListModel(); jList1.setModel(listMod); JTableHeader th = jTable2.getTableHeader(); TableColumnModel tcm = th.getColumnModel(); TableColumn tc = tcm.getColumn(0); tc.setHeaderValue("Time"); tc = tcm.getColumn(1); tc.setHeaderValue("Blood Glucose"); th.repaint(); notesTextArea.setLineWrap(true); notesTextArea.setWrapStyleWord(true); notesTextArea.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { e.consume(); ErrorGUIs.Popup pu = new ErrorGUIs.Popup(); pu.add("Please don't press the ENTER button!"); pu.display(); } } }); }
From source file:stockit.Trader.java
/** * Creates new form Trader/* w w w . j a v a2 s. c o m*/ */ public Trader() { initComponents(); try { DefaultListModel demoList = new DefaultListModel(); DBConnection dbcon = new DBConnection(); dbcon.establishConnection(); Statement stmt = dbcon.con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT C.Name" + " FROM client as C, trader as t, trader_account as tc, account as a" + " WHERE C.Client_SSN = a.Client_SSN AND " + " tc.Trader_SSN = t.Trader_SSN " + " AND a.Trader_SSN = t.Trader_SSN " + " AND tc.username = \"" + username + "\""); while (rs.next()) { demoList.addElement(rs.getString("Name")); } dbcon.con.close(); listOfClients = new JList(demoList); jScrollPane3.setViewportView(listOfClients); //setUpTable(); } catch (Exception ex) { Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.emr.schemas.SchemerMapper.java
/** * Constructor/*from w w w .j a va 2s. co m*/ * @param emrConn {@link Connection} Connection to the EMR database * @param emrDbName {@link String} Database name */ public SchemerMapper(Connection emrConn, String emrDbName) { this.emrConn = emrConn; this.emrDbName = emrDbName; listModel = new DefaultListModel<String>(); initComponents(); this.setClosable(true); SourceTablesListener listSelectionListener = new SourceTablesListener(txtSelectedTables, listOfTables); sourceTablesList.setCellRenderer(new CheckboxListCellRenderer()); sourceTablesList.addListSelectionListener(listSelectionListener); sourceTablesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); sourceTablesList.setSelectionModel(new DefaultListSelectionModel() { @Override public void setSelectionInterval(int index0, int index1) { if (isSelectedIndex(index0)) super.removeSelectionInterval(index0, index1); else super.addSelectionInterval(index0, index1); } }); //getDatabaseMetaData(); final ListUpdater lu = new ListUpdater(); lu.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { switch (event.getPropertyName()) { case "progress": System.out.println("Fetching data from db"); break; case "state": switch ((SwingWorker.StateValue) event.getNewValue()) { case DONE: try { listModel = lu.get(); sourceTablesList.setModel(listModel); } catch (final CancellationException ex) { Logger.getLogger(SourceDataPreview.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(SourceDataPreview.class.getName()).log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { Logger.getLogger(SourceDataPreview.class.getName()).log(Level.SEVERE, null, ex); } break; } break; } } }); lu.execute(); }
From source file:com.sec.ose.osi.ui.frm.main.identification.JListMatchedFiles.java
public JListMatchedFiles() { super(new DefaultListModel()); ListCellRenderer renderer = new IdentificationListCellRenderer(); this.setCellRenderer(renderer); this.addListSelectionListener(new FileSelectionListener()); }
From source file:anslab2.AnsLab2.java
/** * Creates new form AnsLab2GUI1//from w w w. j a v a 2 s .c o m */ public AnsLab2() { //dt = new Test(); model = new DefaultTableModel(); rawlist = new DefaultListModel(); ascendingList = new DefaultListModel(); initComponents(); TypeGroups.add(AlphabeticSelect); TypeGroups.add(StringSelect); TypeGroups.add(NumericSelect); this.setLocationRelativeTo(null); }