List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener
ListSelectionListener
From source file:ANNFileDetect.EditNet.java
public void populateList() { String[] nnames = new String[] { "" }; nnames = sqlite.GetNetworkNames();//from w w w. j a v a 2s .c o m DefaultListModel mdl = new DefaultListModel(); for (int i = 0; i < nnames.length; i++) { mdl.add(i, nnames[i]); } NetList.setModel(mdl); NetList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (evt.getValueIsAdjusting()) { return; } else { String[] images = {}; try { images = sqlite.GetImagesForNetwork(NetList.getSelectedValue().toString()); } catch (Exception e) { System.out.println("exception: " + e.toString()); } DefaultListModel mdl2 = new DefaultListModel(); if (images.length > 0) { for (int i = 0; i < images.length; i++) { mdl2.add(i, images[i]); } } else { mdl2.clear(); thresholdList.setModel(mdl2); } fileList.setModel(mdl2); } } }); fileList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (evt.getValueIsAdjusting()) { return; } else { String[] thresh = sqlite.GetThresholds(NetList.getSelectedValue().toString(), fileList.getSelectedValue().toString()); DefaultListModel mdl3 = new DefaultListModel(); if (thresh.length > 0) { for (int i = 0; i < thresh.length; i++) { String[] vals = thresh[i].split(","); mdl3.add(i, "Range: " + vals[0] + "-" + vals[1] + " Score: " + vals[3] + " Weight: " + vals[2]); } } else { mdl3.clear(); } thresholdList.setModel(mdl3); } } }); }
From source file:com.anrisoftware.prefdialog.miscswing.lists.PopupMenuList.java
private void setupList() { list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override// w w w . ja va 2 s.c o m public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } selectedIndex = list.getSelectedIndex(); } }); }
From source file:AliasBean.java
public AliasBean() { aliVector = new Vector(); aliJList = new JList(); // XXX MUST FIX THIS // aliJList.setSelectionMode(JList.SINGLE_SELECTION); aliJList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { int i = aliJList.getSelectedIndex(); if (i < 0) return; Alias al = (Alias) aliVector.get(i); nameTF.setText(al.getName()); addrTF.setText(al.getAddress()); }//from w w w . j a v a 2 s .c o m }); setLayout(new BorderLayout()); add(BorderLayout.WEST, new JScrollPane(aliJList)); JPanel rightPanel = new JPanel(); add(BorderLayout.EAST, rightPanel); rightPanel.setLayout(new GridLayout(0, 1)); JPanel buttons = new JPanel(); rightPanel.add(buttons); buttons.setLayout(new GridLayout(0, 1, 15, 15)); JButton b; buttons.add(b = new JButton("Set")); b.setToolTipText("Add or Change an alias"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int i = aliJList.getSelectedIndex(); if (i < 0) { // XXX error dialog?? return; } setAlias(i, nameTF.getText(), addrTF.getText()); } }); buttons.add(b = new JButton("Delete")); b.setToolTipText("Delete the selected alias"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int i = aliJList.getSelectedIndex(); if (i < 0) { return; } deleteAlias(i); } }); buttons.add(b = new JButton("Apply")); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.err.println("NOT WRITTEN YET"); } }); JPanel fields = new JPanel(); rightPanel.add(fields); fields.setLayout(new GridLayout(2, 2)); fields.add(new JLabel("Name")); fields.add(nameTF = new JTextField(10)); fields.add(new JLabel("Address")); fields.add(addrTF = new JTextField(20)); }
From source file:components.TableFilterDemo.java
public TableFilterDemo() { super();/*w ww . java2s .c om*/ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); //Create a table with a sorter. MyTableModel model = new MyTableModel(); sorter = new TableRowSorter<MyTableModel>(model); table = new JTable(model); table.setRowSorter(sorter); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true); //For the purposes of this example, better to have a single //selection. table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //When selection changes, provide user with row numbers for //both view and model. table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { int viewRow = table.getSelectedRow(); if (viewRow < 0) { //Selection got filtered away. statusText.setText(""); } else { int modelRow = table.convertRowIndexToModel(viewRow); statusText.setText(String.format("Selected Row in view: %d. " + "Selected Row in model: %d.", viewRow, modelRow)); } } }); //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); //Create a separate form for filterText and statusText JPanel form = new JPanel(new SpringLayout()); JLabel l1 = new JLabel("Filter Text:", SwingConstants.TRAILING); form.add(l1); filterText = new JTextField(); //Whenever filterText changes, invoke newFilter. filterText.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { newFilter(); } public void insertUpdate(DocumentEvent e) { newFilter(); } public void removeUpdate(DocumentEvent e) { newFilter(); } }); l1.setLabelFor(filterText); form.add(filterText); JLabel l2 = new JLabel("Status:", SwingConstants.TRAILING); form.add(l2); statusText = new JTextField(); l2.setLabelFor(statusText); form.add(statusText); SpringUtilities.makeCompactGrid(form, 2, 2, 6, 6, 6, 6); add(form); }
From source file:com.wesley.urban_cuts.client.urbancuts.myFrame.java
/** * Creates new form HomeFrame//w ww . j a v a 2 s. c o m */ public myFrame() { initComponents(); ctx = new ClassPathXmlApplicationContext( "classpath:com/wesley/urban_cuts/app/conf/applicationContext-*.xml"); staffCrudService = (StaffCrudService) ctx.getBean("StaffCrudService"); styleCrudService = (StyleCrudService) ctx.getBean("StyleCrudService"); paymentCrudService = (PaymentCrudService) ctx.getBean("PaymentCrudService"); populate_barbers(); populate_styles(); populate_table(); jList2.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { if (!event.getValueIsAdjusting()) { JList source = (JList) event.getSource(); String selected = source.getSelectedValue().toString(); jTextField1.setText(selected); } } }); jList3.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { if (!event.getValueIsAdjusting()) { JList source = (JList) event.getSource(); String selected2 = source.getSelectedValue().toString(); jTextField3.setText(selected2); Style s = styleCrudService.getByPropertyName("style_name", jTextField3.getText()); jTextField2.setText(Double.toString(s.getPrice())); } } }); }
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 .j a v 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:com.floreantpos.ui.views.CookingInstructionSelectionView.java
private void createUI() { setTitle(Messages.getString("CookingInstructionSelectionView.1")); setTitlePaneText(Messages.getString("CookingInstructionSelectionView.1")); //$NON-NLS-1$ getContentPanel().setBorder(new EmptyBorder(10, 20, 0, 20)); JScrollPane scrollPane = new JScrollPane(); table = new JTable(); table.setRowHeight(35);//from ww w.ja v a2 s .c o m scrollPane.setViewportView(table); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int index = table.getSelectedRow(); if (index < 0) return; CookingInstructionTableModel model = (CookingInstructionTableModel) table.getModel(); CookingInstruction cookingInstruction = model.rowsList.get(index); tfCookingInstruction.setText(cookingInstruction.getDescription()); } }); tfCookingInstruction.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { doFilter(); } @Override public void keyReleased(KeyEvent e) { doFilter(); } @Override public void keyPressed(KeyEvent e) { } }); PosButton btnSave = new PosButton(IconFactory.getIcon("save.png")); btnSave.setText(POSConstants.SAVE.toUpperCase()); btnSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String instruction = tfCookingInstruction.getText(); if (instruction == null || instruction.isEmpty()) { POSMessageDialog.showMessage(Application.getPosWindow(), "Instruction cannot be empty."); return; } CookingInstruction cookingInstruction = new CookingInstruction(); cookingInstruction.setDescription(instruction); CookingInstructionDAO.getInstance().save(cookingInstruction); updateView(); CookingInstructionTableModel model = (CookingInstructionTableModel) table.getModel(); table.getSelectionModel().addSelectionInterval(model.getRowCount() - 1, model.getRowCount() - 1); } }); JPanel contentPanel = new JPanel(new MigLayout("fill,wrap 1,inset 0")); contentPanel.add(scrollPane, "grow"); contentPanel.add(tfCookingInstruction, "h 35!,split 2,grow"); contentPanel.add(btnSave, "h 35!,w 90!"); QwertyKeyPad keyPad = new QwertyKeyPad(); contentPanel.add(keyPad, "grow"); getContentPanel().add(contentPanel); }
From source file:de.quadrillenschule.azocamsyncd.astromode.gui.AstroModeJPanel.java
public AstroModeJPanel() { gp = new GlobalProperties(); initComponents();//from ww w . j a va 2s .c om jobjTable.setModel(new PhotoSeriesTableModel(jobList)); jobjTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (PROGRAMMATIC_SELECTION || (jobjTable.getSelectedRow() < 0)) { return; } PhotoSerie ps = jobList.get(jobjTable.getSelectedRow()); projectTextField.setText(ps.getProject()); seriesTextField.setText(ps.getSeriesName()); numberTextField.setText("" + ps.getNumber()); exposureTextField.setText(Formats.toString(ps.getExposure())); initialDelayTextField.setText(Formats.toString(ps.getInitialDelay())); delayAfterEachTextField.setText(Formats.toString(ps.getDelayAfterEachExposure())); } }); }
From source file:com.sshtools.common.ui.HostsTab.java
/** * Creates a new HostsTab object./*from ww w .j a v a2 s .c o m*/ * * @param hostKeyVerifier */ public HostsTab(AbstractKnownHostsKeyVerification hostKeyVerifier) { super(); this.hostKeyVerifier = hostKeyVerifier; hosts = new JList(model = new HostsListModel()); hosts.setVisibleRowCount(10); hosts.setCellRenderer(new HostRenderer()); hosts.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { setAvailableActions(); } }); remove = new JButton("Remove", new ResourceIcon(REMOVE_ICON)); remove.addActionListener(this); //deny = new JButton("Deny", new ResourceIcon(DENY_ICON)); //deny.addActionListener(this); JPanel b = new JPanel(new GridBagLayout()); b.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0)); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(0, 0, 4, 0); gbc.anchor = GridBagConstraints.NORTH; gbc.weightx = 1.0; UIUtil.jGridBagAdd(b, remove, gbc, GridBagConstraints.REMAINDER); gbc.weighty = 1.0; //UIUtil.jGridBagAdd(b, deny, gbc, GridBagConstraints.REMAINDER); JPanel s = new JPanel(new BorderLayout()); s.add(new JScrollPane(hosts), BorderLayout.CENTER); s.add(b, BorderLayout.EAST); IconWrapperPanel w = new IconWrapperPanel(new ResourceIcon(GLOBAL_ICON), s); // This tab setLayout(new BorderLayout()); add(w, BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); reset(); }
From source file:com.github.alexfalappa.nbspringboot.navigator.RequestMappingNavigatorPanel.java
/** * public no arg constructor needed for system to instantiate provider well *//*from ww w . j av a 2 s. co m*/ public RequestMappingNavigatorPanel() { table = new ETable(); mappedElementsModel = new MappedElementsModel(); mappedElementGatheringTaskFactory = new ElementScanningTaskFactory(table, mappedElementsModel); table.setModel(mappedElementsModel); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setColumnSorted(0, true, 1); table.setDefaultRenderer(RequestMethod.class, new RequestMethodCellRenderer()); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent event) { final int selectedRow = ((ListSelectionModel) event.getSource()).getMinSelectionIndex(); if (event.getValueIsAdjusting() || selectedRow < 0) { return; } final MappedElement mappedElement = mappedElementsModel .getElementAt(table.convertRowIndexToModel(selectedRow)); ElementOpen.open(mappedElement.getFileObject(), mappedElement.getHandle()); try { final DataObject dataObject = DataObject.find(mappedElement.getFileObject()); final EditorCookie editorCookie = dataObject.getLookup().lookup(EditorCookie.class); if (editorCookie != null) { editorCookie.openDocument(); JEditorPane[] p = editorCookie.getOpenedPanes(); if (p.length > 0) { p[0].requestFocus(); } } } catch (IOException e) { } } }); final JPanel panel = new JPanel(new BorderLayout()); panel.add(new JScrollPane(table), BorderLayout.CENTER); this.component = panel; this.contextListener = new LookupListener() { @Override public void resultChanged(LookupEvent le) { } }; }