List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener
ListSelectionListener
From source file:de.rub.syssec.saaf.gui.frame.CfgSelectorFrame.java
/** * A frame to generate and open Control Flow Graphs. CFGs are created using mxGraph * and are saved as PNGs.//from w w w. ja v a 2s. com * * @param smaliClass the smali class to select methods from */ public CfgSelectorFrame(ClassInterface smaliClass) { super(smaliClass.getFullClassName(true), true, true, true, true); this.smaliClass = smaliClass; listModel = new MethodTableModel(smaliClass); list.setModel(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { int viewRow = list.getSelectedRow(); if (viewRow <= 0) { showButton.setEnabled(false); } else { showButton.setEnabled(true); } } }); JScrollPane listScrollPane = new JScrollPane(list); ActionListener al = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(SHOW_OPERATION)) { generateAndShowCfg(true); } else if (e.getActionCommand().equals(GENERATE_OPERATION)) { generateAndShowCfg(false); } } }; generateButton = new JButton(GENERATE_OPERATION); generateButton.setActionCommand(GENERATE_OPERATION); generateButton.addActionListener(al); showButton = new JButton(SHOW_OPERATION); showButton.setEnabled(false); showButton.addActionListener(al); saveCfgCheckBox = new JCheckBox("Save a copy"); saveCfgCheckBox.setToolTipText("Save a copy in the configured CFG folder upon generation."); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(generateButton); buttonPane.add(saveCfgCheckBox); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel filler = new JPanel(); filler.setPreferredSize(new Dimension(10, 10)); buttonPane.add(filler); buttonPane.add(showButton); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); this.setPreferredSize(new Dimension(500, 250)); this.pack(); this.setVisible(true); }
From source file:com.github.alexfalappa.nbspringboot.projects.customizer.CfgPropsDialog.java
/** Creates new form CfgPropsDialog */ public CfgPropsDialog(java.awt.Dialog parent) { super(parent, true); initComponents();/*w w w .ja v a 2 s. c o m*/ // retrieve some flads from prefs final Preferences prefs = NbPreferences.forModule(PrefConstants.class); final boolean bDeprLast = prefs.getBoolean(PREF_DEPR_SORT_LAST, true); bDeprErrorShow = prefs.getBoolean(PREF_DEPR_ERROR_SHOW, false); // setup props sorting this.sortedProps = new TreeSet<>(new ConfigurationMetadataComparator(bDeprLast)); // setup property list lCfgProps.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final ConfigurationMetadataProperty selectedValue = lCfgProps.getSelectedValue(); if (selectedValue != null) { tpDetails.setText(Utils.cfgPropDetailsHtml(selectedValue)); tpDetails.setCaretPosition(0); } } } }); // set default button rootPane.setDefaultButton(bOk); // close dialog with ESC key final ActionListener escAction = new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { CfgPropsDialog.this.setVisible(false); } }; rootPane.registerKeyboardAction(escAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); }
From source file:com.mirth.connect.client.ui.alert.AlertChannelPane.java
private void makeChannelTable() { ChannelTreeTableModel model = new ChannelTreeTableModel(); model.setColumnIdentifiers(Arrays.asList(new String[] { "test" })); channelTreeTable.setTreeTableModel(model); channelTreeTable.setDoubleBuffered(true); channelTreeTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); channelTreeTable.setHorizontalScrollEnabled(true); channelTreeTable.packTable(UIConstants.COL_MARGIN); channelTreeTable.setRowHeight(UIConstants.ROW_HEIGHT); channelTreeTable.setOpaque(true);/* w w w . ja v a 2s .c o m*/ channelTreeTable.setRowSelectionAllowed(true); channelTreeTable.putClientProperty("JTree.lineStyle", "Horizontal"); channelTreeTable.setAutoCreateColumnsFromModel(false); channelTreeTable.setShowGrid(true, true); channelTreeTable.setTableHeader(null); channelTreeTable.setDragEnabled(false); channelTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { boolean enabled = channelTreeTable.getSelectedRowCount() > 0; enableButton.setEnabled(enabled); disableButton.setEnabled(enabled); } } }); channelTreeTable.setTreeCellRenderer(new TreeCellRenderer() { private JLabel label = new JLabel(); @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value != null) { if (value instanceof ChannelTreeTableNode) { ChannelTreeTableNode channelNode = (ChannelTreeTableNode) value; ImageIcon icon; if (channelNode.getChildCount() == 0) { // node is a channel node with no children icon = channelNode.isEnabled() ? UIConstants.ICON_BULLET_GREEN : UIConstants.ICON_BULLET_RED; } else { // node is a channel node with children boolean hasDisabled = false; boolean hasEnabled = false; for (int i = 0; i < channelNode.getChildCount(); i++) { ConnectorTreeTableNode connectorNode = (ConnectorTreeTableNode) channelNode .getChildAt(i); if (connectorNode.isEnabled()) { hasEnabled = true; } else { hasDisabled = true; } } if (hasEnabled && hasDisabled) { icon = UIConstants.ICON_BULLET_YELLOW; } else if (hasDisabled) { icon = UIConstants.ICON_BULLET_RED; } else if (hasEnabled) { icon = UIConstants.ICON_BULLET_GREEN; } else { // This should never occur because a channel should never be a leaf. icon = UIConstants.ICON_BULLET_RED; } } label.setText(channelNode.getChannelName()); label.setIcon(icon); } else if (value instanceof ConnectorTreeTableNode) { ConnectorTreeTableNode connectorNode = (ConnectorTreeTableNode) value; ImageIcon icon = connectorNode.isEnabled() ? UIConstants.ICON_BULLET_GREEN : UIConstants.ICON_BULLET_RED; label.setText(connectorNode.getConnectorName()); label.setIcon(icon); } } return label; } }); channelTreeTable.expandAll(); }
From source file:Main.java
public Main() { 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);/*w w w . j a v a2s . 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: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 av a2s . c om*/ 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 ww .j av a 2 s. c om 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:com.compomics.cell_coord.gui.controller.summary.SummaryDataController.java
/** * Initialize main view.// w w w . ja va 2 s . c o m */ 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:org.nekorp.workflow.desktop.view.NavegadorServiciosView.java
@Override public void iniciaVista() { initComponents();//from w w w .ja va2 s .c om bindingManager.registerBind(servicioLoadedListMetadata, "serviciosNuevos", modeloServicioNuevoList); bindingManager.registerBind(servicioLoadedListMetadata, "servicios", modeloServicioList); this.bindingManager.registerBind(servicioMetaData, "servicioActual", new ReadOnlyBinding() { @Override public void notifyUpdate(Object origen, String property, Object value) { internalUpdateOnProcess = true; ServicioLoaded servicio = (ServicioLoaded) value; listaServicioCargado.clearSelection(); listaServicioNuevo.clearSelection(); if (servicio != null) { if (servicio.isNuevo()) { listaServicioNuevo.setSelectedIndex(modeloServicioNuevoList.indexof(servicio)); } else { listaServicioCargado.setSelectedIndex(modeloServicioList.indexof(servicio)); } } internalUpdateOnProcess = false; } }); this.listaServicioNuevo.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (listaServicioNuevo.getSelectedIndex() < modeloServicioNuevoList.getSize() && listaServicioNuevo.getSelectedIndex() > -1) { if (!internalUpdateOnProcess && !e.getValueIsAdjusting() && !listaServicioNuevo.isSelectionEmpty()) { aplication.cambiarServicio( modeloServicioNuevoList.getElementAt(listaServicioNuevo.getSelectedIndex())); } } } }); this.listaServicioCargado.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (listaServicioCargado.getSelectedIndex() < modeloServicioList.getSize() && listaServicioCargado.getSelectedIndex() > -1) { if (!internalUpdateOnProcess && !e.getValueIsAdjusting() && !listaServicioCargado.isSelectionEmpty()) { aplication.cambiarServicio( modeloServicioList.getElementAt(listaServicioCargado.getSelectedIndex())); } } } }); }
From source file:TableFilterDemo.java
public TableFilterDemo() { super();/* ww w . j av a 2 s.c o m*/ 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:au.com.jwatmuff.eventmanager.gui.admin.WithdrawPlayerDialog.java
/** Creates new form WithdrawPlayerDialog */ public WithdrawPlayerDialog(java.awt.Frame parent, boolean modal, Database database, TransactionNotifier notifier) {/*from w w w .j av a 2s . co m*/ super(parent, modal); initComponents(); setLocationRelativeTo(null); this.database = database; this.notifier = notifier; divisionTableModel = new DivisionTableModel(); divisionTableModel.updateFromDatabase(); divisionTable.setModel(divisionTableModel); divisionTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); divisionTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { playerTableModel.updateFromDatabase(); } }); notifier.addListener(divisionTableModel, Pool.class); playerTableModel = new PlayerTableModel(); playerTable.setModel(playerTableModel); playerTable.setSelectionModel(new NullSelectionModel()); // disable selection // set up cell editor for status column // see PlayerTableModel.setValueAt() for how edits to cells are handled playerTable.getColumnModel().getColumn(1) .setCellEditor(new DefaultCellEditor(new JComboBox<Status>(statuses))); playerTable.getColumnModel().getColumn(1).setCellRenderer(new ComboBoxCellRenderer(Status.values())); // sort by name playerTable.getRowSorter().setSortKeys(Arrays.asList(new RowSorter.SortKey(0, SortOrder.ASCENDING))); notifier.addListener(playerTableModel, PlayerPool.class); }