List of usage examples for javax.swing.event ListSelectionEvent getValueIsAdjusting
public boolean getValueIsAdjusting()
From source file:JListDemo.java
JListDemo(String s) { super(s);//from w ww .j av a2 s . c o m Container cp = getContentPane(); cp.setLayout(new FlowLayout()); ArrayList data = new ArrayList(); data.add("Hi"); data.add("Hello"); data.add("Goodbye"); data.add("Adieu"); data.add("Adios"); list = new JList(data.toArray()); list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (evt.getValueIsAdjusting()) return; System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex()); } }); cp.add(list, BorderLayout.CENTER); }
From source file:ListIt.java
public ListIt() { JFrame f = new JFrame(); final PartsListModel pcm = new PartsListModel(); ListCellRenderer lcr = new MyLabelRenderer(); JList jl = new JList(pcm); jl.setCellRenderer(lcr);//w ww . ja va 2 s. co m ListSelectionModel lsm = jl.getSelectionModel(); lsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jl.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { String element[] = (String[]) pcm.getElementAt(e.getFirstIndex()); System.out.println(element[0] + " : " + element[1] + " : " + element[2]); } } }); JScrollPane jsp = new JScrollPane(jl); JComboBox jc = new JComboBox(pcm); jc.setRenderer(lcr); JButton jb = new JButton("Add Merchandise"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pcm.addElement(partsList[(int) (Math.random() * partsList.length)]); } }); Container c = f.getContentPane(); c.add(jsp, BorderLayout.NORTH); c.add(jc, BorderLayout.CENTER); c.add(jb, BorderLayout.SOUTH); f.setSize(250, 250); f.show(); }
From source file:Main.java
public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { if (list.getSelectedIndex() == -1) { fireButton.setEnabled(false); } else {// w w w .ja v a2 s . com fireButton.setEnabled(true); } } }
From source file:com.anrisoftware.prefdialog.miscswing.lists.PopupMenuList.java
private void setupList() { list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override/* w w w . j ava2 s . c o m*/ public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } selectedIndex = list.getSelectedIndex(); } }); }
From source file:com.anrisoftware.prefdialog.miscswing.lists.ActionList.java
private void setupList() { list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override/* ww w .j a va2s . c o m*/ public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { fireAction(); } } }); list.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { fireAction(); } }); list.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getExtendedKeyCode() == KeyEvent.VK_SPACE) { fireAction(); } if (e.getExtendedKeyCode() == KeyEvent.VK_ENTER) { fireAction(); } } }); }
From source file:SharedListSelectionHandler.java
public void valueChanged(ListSelectionEvent e) { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); int firstIndex = e.getFirstIndex(); int lastIndex = e.getLastIndex(); boolean isAdjusting = e.getValueIsAdjusting(); System.out.println("Event for indexes " + firstIndex + " - " + lastIndex + "; isAdjusting is " + isAdjusting + "; selected indexes:"); if (lsm.isSelectionEmpty()) { System.out.println(" <none>"); } else {//from ww w . j a v a2 s . com // Find out which indexes are selected. int minIndex = lsm.getMinSelectionIndex(); int maxIndex = lsm.getMaxSelectionIndex(); for (int i = minIndex; i <= maxIndex; i++) { if (lsm.isSelectedIndex(i)) { System.out.println(" " + i); } } } }
From source file:components.ListDemo.java
public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { if (list.getSelectedIndex() == -1) { //No selection, disable fire button. fireButton.setEnabled(false); } else {/*from ww w .j a v a 2 s .c o m*/ //Selection, enable the fire button. fireButton.setEnabled(true); } } }
From source file:ListDemo.java
public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { if (list.getSelectedIndex() == -1) { // No selection, disable fire button. fireButton.setEnabled(false); } else {/* w ww .ja va 2 s . c om*/ // Selection, enable the fire button. fireButton.setEnabled(true); } } }
From source file:com.compomics.cell_coord.gui.controller.summary.SummaryDataController.java
/** * Initialize main view.//from ww w . j a v a2 s. com */ private void initSummaryDataPanel() { // create new object summaryDataPanel = new SummaryDataPanel(); // format the tables JTableHeader samplesHeader = summaryDataPanel.getSamplesTable().getTableHeader(); samplesHeader.setBackground(GuiUtils.getHeaderColor()); samplesHeader.setFont(GuiUtils.getHeaderFont()); samplesHeader.setReorderingAllowed(false); JTableHeader tracksHeader = summaryDataPanel.getTracksTable().getTableHeader(); tracksHeader.setBackground(GuiUtils.getHeaderColor()); tracksHeader.setFont(GuiUtils.getHeaderFont()); tracksHeader.setReorderingAllowed(false); JTableHeader trackSpotsHeader = summaryDataPanel.getTrackSpotsTable().getTableHeader(); trackSpotsHeader.setBackground(GuiUtils.getHeaderColor()); trackSpotsHeader.setFont(GuiUtils.getHeaderFont()); trackSpotsHeader.setReorderingAllowed(false); summaryDataPanel.getSamplesTable().setRowSelectionAllowed(true); summaryDataPanel.getSamplesTable().setColumnSelectionAllowed(false); summaryDataPanel.getSamplesTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); summaryDataPanel.getTracksTable().setRowSelectionAllowed(true); summaryDataPanel.getTracksTable().setColumnSelectionAllowed(false); summaryDataPanel.getTracksTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // if you click on a sample, the relative tracks are shown in another table summaryDataPanel.getSamplesTable().getSelectionModel() .addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int selectedRow = summaryDataPanel.getSamplesTable().getSelectedRow(); if (selectedRow != -1) { Sample selectedSample = loadTracksController.getSamples().get(selectedRow); showTracksInTable(selectedSample); } } } }); // if you click on a track, the relative spots are shown in another table summaryDataPanel.getTracksTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Sample selectedSample = loadTracksController.getSamples() .get(summaryDataPanel.getSamplesTable().getSelectedRow()); int selectedRow = summaryDataPanel.getTracksTable().getSelectedRow(); if (selectedRow != -1) { Track selectedTrack = selectedSample.getTracks().get(selectedRow); showSpotsInTable(selectedTrack); } } } }); // add view to parent controller loadTracksController.getMainFrame().getSummaryDataParentPanel().add(summaryDataPanel, gridBagConstraints); }
From source file:com.compomics.cell_coord.gui.controller.computation.ComputationMainController.java
/** * Initialize some GUI components./* ww w . ja va2 s.c om*/ */ private void initMainView() { // format the tables JTableHeader samplesHeader = getMainFrame().getSamplesTable().getTableHeader(); samplesHeader.setBackground(GuiUtils.getHeaderColor()); samplesHeader.setFont(GuiUtils.getHeaderFont()); samplesHeader.setReorderingAllowed(false); JTableHeader tracksHeader = getMainFrame().getTracksTable().getTableHeader(); tracksHeader.setBackground(GuiUtils.getHeaderColor()); tracksHeader.setFont(GuiUtils.getHeaderFont()); tracksHeader.setReorderingAllowed(false); getMainFrame().getSamplesTable().setRowSelectionAllowed(true); getMainFrame().getSamplesTable().setColumnSelectionAllowed(false); getMainFrame().getSamplesTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); getMainFrame().getTracksTable().setRowSelectionAllowed(true); getMainFrame().getTracksTable().setColumnSelectionAllowed(false); getMainFrame().getTracksTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // if you click on a sample, the relative tracks are shown in another table getMainFrame().getSamplesTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int selectedRow = getMainFrame().getSamplesTable().getSelectedRow(); if (selectedRow != -1) { Sample selectedSample = getSamples().get(selectedRow); showTracksInTable(selectedSample); computationDataController.computeSample(selectedSample); // call child controller to show sample data in table computationDataController.showSampleData(selectedSample); // call child controller to plot whatever we need to plot } } } }); // if you click on a track, the relative spots are shown in another table getMainFrame().getTracksTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Sample selectedSample = getSamples().get(getMainFrame().getSamplesTable().getSelectedRow()); int selectedRow = getMainFrame().getTracksTable().getSelectedRow(); if (selectedRow != -1) { Track selectedTrack = selectedSample.getTracks().get(selectedRow); // call child controller to show track data in table computationDataController.showStepData(selectedTrack); computationDataController.showTrackData(selectedTrack); // call child controller to plot whatever we need to plot computationDataController.plotStepData(selectedTrack); computationDataController.plotTrackData(selectedTrack); } } } }); }