List of usage examples for javax.swing.event ListSelectionEvent getSource
public Object getSource()
From source file:SimpleTableSelectionDemo.java
public SimpleTableSelectionDemo() { super(new GridLayout(1, 0)); final String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; final Object[][] data = { { "Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false) }, { "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) }, { "Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false) }, { "Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true) }, { "Philip", "Milne", "Pool", new Integer(10), new Boolean(false) } }; final JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);/*from ww w . j ava2 s . c o m*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); if (ALLOW_ROW_SELECTION) { // true by default ListSelectionModel rowSM = table.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { // Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No rows are selected."); } else { int selectedRow = lsm.getMinSelectionIndex(); System.out.println("Row " + selectedRow + " is now selected."); } } }); } else { table.setRowSelectionAllowed(false); } if (ALLOW_COLUMN_SELECTION) { // false by default if (ALLOW_ROW_SELECTION) { // We allow both row and column selection, which // implies that we *really* want to allow individual // cell selection. table.setCellSelectionEnabled(true); } table.setColumnSelectionAllowed(true); ListSelectionModel colSM = table.getColumnModel().getSelectionModel(); colSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { // Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No columns are selected."); } else { int selectedCol = lsm.getMinSelectionIndex(); System.out.println("Column " + selectedCol + " is now selected."); } } }); } if (DEBUG) { table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { printDebugData(table); } }); } // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); // Add the scroll pane to this panel. add(scrollPane); }
From source file:components.SimpleTableSelectionDemo.java
public SimpleTableSelectionDemo() { super(new GridLayout(1, 0)); final String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; final Object[][] data = { { "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) }, { "John", "Doe", "Rowing", new Integer(3), new Boolean(true) }, { "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) }, { "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) }, { "Joe", "Brown", "Pool", new Integer(10), new Boolean(false) } }; final JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);/* w w w . j a v a 2 s.co m*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); if (ALLOW_ROW_SELECTION) { // true by default ListSelectionModel rowSM = table.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { //Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No rows are selected."); } else { int selectedRow = lsm.getMinSelectionIndex(); System.out.println("Row " + selectedRow + " is now selected."); } } }); } else { table.setRowSelectionAllowed(false); } if (ALLOW_COLUMN_SELECTION) { // false by default if (ALLOW_ROW_SELECTION) { //We allow both row and column selection, which //implies that we *really* want to allow individual //cell selection. table.setCellSelectionEnabled(true); } table.setColumnSelectionAllowed(true); ListSelectionModel colSM = table.getColumnModel().getSelectionModel(); colSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { //Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No columns are selected."); } else { int selectedCol = lsm.getMinSelectionIndex(); System.out.println("Column " + selectedCol + " is now selected."); } } }); } if (DEBUG) { table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { printDebugData(table); } }); } //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); }
From source file:SimpleTableSelectionDemo.java
public SimpleTableSelectionDemo() { super(new GridLayout(1, 0)); final String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; final Object[][] data = { { "Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false) }, { "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) }, { "Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false) }, { "Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true) }, { "Philip", "Milne", "Pool", new Integer(10), new Boolean(false) } }; final JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); if (ALLOW_ROW_SELECTION) { // true by default ListSelectionModel rowSM = table.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { //Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No rows are selected."); } else { int selectedRow = lsm.getMinSelectionIndex(); System.out.println("Row " + selectedRow + " is now selected."); }// w w w . j av a 2 s. c o m } }); } else { table.setRowSelectionAllowed(false); } if (ALLOW_COLUMN_SELECTION) { // false by default if (ALLOW_ROW_SELECTION) { //We allow both row and column selection, which //implies that we *really* want to allow individual //cell selection. table.setCellSelectionEnabled(true); } table.setColumnSelectionAllowed(true); ListSelectionModel colSM = table.getColumnModel().getSelectionModel(); colSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { //Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No columns are selected."); } else { int selectedCol = lsm.getMinSelectionIndex(); System.out.println("Column " + selectedCol + " is now selected."); } } }); } if (DEBUG) { table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { printDebugData(table); } }); } //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); }
From source file:gui.TwopointPWDPanel.java
public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return;// w w w . j ava 2s . c o m if (e.getSource() == markerTable.getSelectionModel()) { processMarkerTableClick(e); } else { processPhaseTableClick(e); } }
From source file:misc.TextBatchPrintingDemo.java
/** * Called when the print list selection state is changed. This is the * {@code ListSelectionListener} method. *///from w w w .ja v a 2 s . c o m public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int index = ((JList) e.getSource()).getSelectedIndex(); if (index >= 0) { // Load the currently selected URL into the page browser. PageItem item = (PageItem) selectedPages.getModel().getElementAt(index); URL page = item.getPage(); if (!page.equals(pageItem.getPage())) { setPage(page); } } } }
From source file:gui.TwopointPWDPanel.java
private void processPhaseTableClick(ListSelectionEvent e) { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) return;/* ww w .ja va 2 s . c o m*/ // Which two markers are selected? CMarker cm1 = (CMarker) markerTable.getValueAt(markerTable.getSelectedRow(), 1); CMarker cm2 = (CMarker) phaseTable.getValueAt(phaseTable.getSelectedRow(), 1); if (cm1 == cm2) { m1Label.setText(""); m2Label.setText(""); } else { int cm1i = order.getLinkageGroup().getMarkerIndexBySafeName(cm1.safeName); int cm2i = order.getLinkageGroup().getMarkerIndexBySafeName(cm2.safeName); if (order.translateIndexes != null) { cm1i = order.translatePPIndexes[order.getLinkageGroup().getMarkerIndexBySafeName(cm1.safeName)]; cm2i = order.translatePPIndexes[order.getLinkageGroup().getMarkerIndexBySafeName(cm2.safeName)]; } PhasePair pp = order.getPhasePairArray()[cm1i][cm2i]; // First determine the marker with the longest name int length1 = cm1.marker.getName().length(); int length2 = cm2.marker.getName().length(); int max = length1 >= length2 ? length1 : length2; // Need to determine *which way round* the phases are // stored/displayed if (pp.compare(cm1, cm2) == 1) { m1Label.setText(cm1.marker.getName(max) + " " + pp.phase1); m2Label.setText(cm2.marker.getName(max) + " " + pp.phase2); } else { m1Label.setText(cm1.marker.getName(max) + " " + pp.phase2); m2Label.setText(cm2.marker.getName(max) + " " + pp.phase1); } } }
From source file:gui.TwopointPWDPanelnonsnp.java
private void processPhaseTableClick(ListSelectionEvent e) { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) return;/*from ww w . j a va2 s. c om*/ // Which two markers are selected? CMarker cm1 = (CMarker) markerTable.getValueAt(markerTable.getSelectedRow(), 1); CMarker cm2 = (CMarker) phaseTable.getValueAt(phaseTable.getSelectedRow(), 1); if (cm1 == cm2) { m1Label.setText(""); m2Label.setText(""); } else { PhasePair pp = order.getPhasePairArray()[cm1.getSafeNameSuffix() - 1][cm2.getSafeNameSuffix() - 1]; // First determine the marker with the longest name int length1 = cm1.marker.getName().length(); int length2 = cm2.marker.getName().length(); int max = length1 >= length2 ? length1 : length2; // Need to determine *which way round* the phases are // stored/displayed if (pp.compare(cm1, cm2) == 1) { m1Label.setText(cm1.marker.getName(max) + " " + pp.phase1); m2Label.setText(cm2.marker.getName(max) + " " + pp.phase2); } else { m1Label.setText(cm1.marker.getName(max) + " " + pp.phase2); m2Label.setText(cm2.marker.getName(max) + " " + pp.phase1); } } }
From source file:ftpclientgui.MainWindow.java
/** * List selection changed/*from w ww.j a v a 2 s. c om*/ * @param e */ @Override public void valueChanged(ListSelectionEvent e) { if (e.getSource().equals(dirList)) { try { //try to change the folder in FTPManager if (mngr != null && mngr.changeDirectory(dirList.getCurrentFolderPath())) { this.labLocation.setText(dirList.getCurrentFolderPath()); updateDirFilesList(); } } catch (IOException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:maltcms.ui.nb.pipelineRunner.ui.PipelineRunnerTopComponent.java
@Override public void valueChanged(ListSelectionEvent lse) { if (lse.getSource() == processList) { MaltcmsLocalHostExecution mlhe = (MaltcmsLocalHostExecution) processList.getSelectedValue(); if (mlhe != null) { if (mlhe.getProgressHandle() == null) { runButton.setEnabled(true); stopButton.setEnabled(false); } else { runButton.setEnabled(false); stopButton.setEnabled(true); }/*from w ww .ja v a2s . c o m*/ } } if (lse.getSource() == runningProcessList) { MaltcmsLocalHostExecution mlhe = (MaltcmsLocalHostExecution) runningProcessList.getSelectedValue(); if (mlhe != null) { if (mlhe.getProgressHandle() == null) { runButton.setEnabled(true); stopButton.setEnabled(false); } else { runButton.setEnabled(false); stopButton.setEnabled(true); } } } }
From source file:com.funambol.email.admin.user.ResultSearchUserPanel.java
/** * Set up graphic elements for this panel. * * @throws Exception if error occures during creation of the panel *//*from w w w . ja va 2 s.c o m*/ private void init() throws Exception { // create objects to display this.setLayout(new BorderLayout()); this.setBorder(BorderFactory.createEmptyBorder()); // create a model for the user table and pass it to the JTable object model = new UserTableModel(); table = new JTable(model); table.setShowGrid(true); table.setAutoscrolls(true); table.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); JScrollPane scrollpane = new JScrollPane(table); table.setPreferredScrollableViewportSize(new Dimension(800, 200)); table.setFont(GuiFactory.defaultTableFont); table.getTableHeader().setFont(GuiFactory.defaultTableHeaderFont); this.add(scrollpane, BorderLayout.CENTER); // // Select user. // table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ListSelectionModel rowSM = table.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { if (event.getValueIsAdjusting()) { return; } ListSelectionModel lsm = (ListSelectionModel) event.getSource(); if (lsm.isSelectionEmpty()) { selectedUser = null; } else { int selectedRow = lsm.getMinSelectionIndex(); selectedUser = users[selectedRow]; } } }); rowSM.clearSelection(); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { if (event.getClickCount() < 2) { return; } // // If the selected user is already associated to an account // then insertion process can't go on. // String userName = selectedUser.getUsername(); String value[] = new String[] { userName }; WhereClause wc = new WhereClause("username", value, WhereClause.OPT_EQ, true); MailServerAccount[] tmp = null; try { tmp = WSDao.getAccounts(wc); } catch (Exception e) { } if (tmp.length > 0) { StringBuilder sb = new StringBuilder("The user "); sb.append(userName).append(" is already associated to an account"); Object[] options = { "OK" }; JOptionPane.showOptionDialog(null, sb.toString(), "Warning", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); } else { // // Go to next step. // step.goToNextStep(); } } }); }