List of usage examples for javax.swing.event ListSelectionEvent getValueIsAdjusting
public boolean getValueIsAdjusting()
From source file:table.TablePanel.java
public TablePanel(JPanel parent, GridBagConstraints c) { this.parent = parent; this.c = c;//from w w w . j a v a 2 s .co m dataHandler = null; data = new ArrayList<>(); selectedRows = new ArrayList<>(); tableModel = new MyTableModel(data); table = new JTable(tableModel); table.getColumnModel().getColumn(0).setResizable(false); table.getColumnModel().getColumn(0).setMaxWidth(60); table.getColumnModel().getColumn(1).setResizable(false); table.getColumnModel().getColumn(1).setMaxWidth(50); table.getColumnModel().getColumn(2).setMaxWidth(90); table.getColumnModel().getColumn(49).setMaxWidth(60); for (int i = 0; i < tableModel.getColumnCount(); i++) { if (i > 14 && i < 31) { table.getColumnModel().getColumn(i).setMaxWidth(70); } else if (tableModel.columnNamesTemp[i].contains("LEVEL")) { if (tableModel.columnNamesTemp[i].equals("QEC LEVEL")) { table.getColumnModel().getColumn(i).setMinWidth(90); table.getColumnModel().getColumn(i).setMaxWidth(200); } else { table.getColumnModel().getColumn(i).setMaxWidth(90); } if (tableModel.columnNamesTemp[i - 1].equals("Work Pace")) { table.getColumnModel().getColumn(i - 1).setMinWidth(90); table.getColumnModel().getColumn(i - 1).setMaxWidth(150); } else { table.getColumnModel().getColumn(i - 1).setMaxWidth(90); } } else { // table.getColumnModel().getColumn(i).setMinWidth(120); // table.getColumnModel().getColumn(i).setMaxWidth(250); } } table.getColumnModel().getColumn(table.getColumnCount() - 1).setMaxWidth(60); table.getColumnModel().getColumn(table.getColumnCount() - 1).setResizable(false); table.setRowSelectionAllowed(true); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (!dataHandler.getDeleting() && (table.getSelectedRow() != -1) && e.getColumn() != table.getColumnCount() - 1 && e.getColumn() != 1) { int row = table.getSelectedRow(); int col = e.getColumn(); if (col == 0 && (boolean) table.getValueAt(row, col) == true) { if (!selectedRows.contains((Integer) row)) selectedRows.add(row); } else if (col == 0 && (boolean) table.getValueAt(row, col) == false) { selectedRows.remove((Object) row); } else if (col != 0 && (boolean) table.getValueAt(row, table.getColumnCount() - 1)) { dataHandler.dataEdited(); } } } }); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { private int count = 0; @Override public void valueChanged(ListSelectionEvent arg0) { if (count > 1 && !arg0.getValueIsAdjusting()) { int[] draggedRows = table.getSelectedRows(); for (int i = 0; i < draggedRows.length; i++) if (selectedRows.contains((Integer) draggedRows[i])) { selectedRows.remove((Integer) draggedRows[i]); table.setValueAt(false, draggedRows[i], 0); } else { selectedRows.add((Integer) draggedRows[i]); table.setValueAt(true, draggedRows[i], 0); } // Finalize count = 0; } else if (arg0.getValueIsAdjusting()) count++; else count = 0; } }); // { // // @Override // public Component prepareRenderer(TableCellRenderer renderer, // int row, int column) { // JLabel label = (JLabel) super.prepareRenderer(renderer, row, column); // if ((boolean) table.getValueAt(row, table.getColumnCount() - 1) == // false) { // if ((int) row % 2 == 0) { // label.setBackground(new Color(244, 226,215)); // } else { // label.setBackground(new Color(241, 220,205)); // } // } else { // if ((int) row% 2 == 0) { // label.setBackground(new Color(255, 255, 255)); // } else { // label.setBackground(new Color(252, 252, 252)); // } // // } // if(table.getSelectedRow()==row) // label.setBackground(Color.LIGHT_GRAY); // return label; // } // }; // table.prepareRenderer(null, WIDTH, WIDTH); // table.setRowSelectionAllowed(true); // table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setDefaultRenderer(Object.class, new MyTableCellRenderer()); // { // // @Override // public Component getTableCellRendererComponent(JTable table, Object // value, boolean isSelected, boolean hasFocus, int row, int column) { // JLabel label = (JLabel) table.prepareRenderer(null, row, column); // if ((boolean) table.getValueAt(row, table.getColumnCount() - 1) == // false) { // if ((int) row % 2 == 0) { // label.setBackground(new Color(244, 226,215)); // } else { // label.setBackground(new Color(241, 220,205)); // } // } else { // if ((int) row% 2 == 0) { // label.setBackground(new Color(255, 255, 255)); // } else { // label.setBackground(new Color(252, 252, 252)); // } // // } // if(table.getSelectedRow()==row) // label.setBackground(Color.LIGHT_GRAY); // return label; // } // }); // { // // @Override // public Component getTableCellRendererComponent(JTable table, Object // value, boolean isSelected, boolean hasFocus, int row, int column) { // Component cell= table.getCellRenderer(row, // column).getTableCellRendererComponent(table, value, isSelected, // hasFocus, row, column); // // // for(int i=1;i<table.getRowCount();i++) { // if((boolean)table.getValueAt(i, table.getColumnCount()-1) ==false) // { // setForeground(Color.black); // setBackground(Color.red); // } // else // { // setBackground(Color.white); // setForeground(Color.black); // } // } // return cell; // } // }); // DefaultTableCellRenderer rightRenderer = new // DefaultTableCellRenderer(); // rightRenderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT); for (int i = 0; i < tableModel.getColumnCount(); i++) { table.getTableHeader().getColumnModel().getColumn(i) .setHeaderRenderer(new HeaderRenderer(table, alignments[1])); // table.getColumnModel().getColumn(i).setCellRenderer(new // MyTableCellRenderer()); } table.getTableHeader().setReorderingAllowed(false); table.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); table.setRowHeight(25); // table.setPreferredScrollableViewportSize(new Dimension(10000, 200)); // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); // JViewport tableView = new JViewport(); // tableView.add(table); // scrollPane.setViewport(tableView); parent.setSize(table.getWidth(), table.getHeight()); // parent.setPreferredSize(new Dimension(70000,10000)); // scrollPane.setVerticalScrollBar(new JScrollBar(JScrollBar.VERTICAL)); // scrollPane.setHorizontalScrollBar(new JScrollBar(JScrollBar.HORIZONTAL)); // Add the scroll pane to this panel. // parent.add(table.getTableHeader()); // parent.add(table, c); // Add header in NORTH slot parent.add(table.getTableHeader(), BorderLayout.NORTH); // Add table itself to CENTER slot parent.add(table, BorderLayout.CENTER); }
From source file:com.projity.pm.graphic.chart.ChartLegend.java
JList getListInstance(boolean cost) { final JList list = new JList() { // do not want to update the UI. see below also private static final long serialVersionUID = 1L; public void updateUI() { if (!Environment.isNewLook()) super.updateUI(); }/*w w w .ja va 2s. co m*/ }; if (Environment.isNewLook()) // The PLAF can override the custom renderer. This avoids that list.setUI(new BasicListUI()); list.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setCellRenderer(new ListRenderer()); setListFields(list, cost); if (!simple) { list.setSelectedIndex(0); // start off with first choice selected list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (chartInfo.isRestoring()) // don't want to listen if updating from workspace return; if (e.getValueIsAdjusting() == false) { chartInfo.setTraces(list.getSelectedValues()); } } }); } return list; }
From source file:com.wesley.urban_cuts.client.urbancuts.myFrame.java
/** * Creates new form HomeFrame//from w w w .jav a2 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:com.mirth.connect.client.ui.EditMessageDialog.java
private void initSourceMapTable(Map<String, Object> sourceMap) { Object[][] data = new Object[sourceMap.size()][2]; int i = 0;/*from www.j av a 2 s .com*/ for (Entry<String, Object> entry : sourceMap.entrySet()) { data[i][0] = entry.getKey(); data[i][1] = entry.getValue(); i++; } sourceMapTable = new MirthTable(); sourceMapTable.setModel(new RefreshTableModel(data, new Object[] { "Variable", "Value" }) { @Override public boolean isCellEditable(int row, int column) { return true; } }); sourceMapTable.setDragEnabled(false); sourceMapTable.setRowSelectionAllowed(true); sourceMapTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); sourceMapTable.setRowHeight(UIConstants.ROW_HEIGHT); sourceMapTable.setFocusable(false); sourceMapTable.setOpaque(true); sourceMapTable.getTableHeader().setResizingAllowed(false); sourceMapTable.getTableHeader().setReorderingAllowed(false); sourceMapTable.setSortable(true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { sourceMapTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } sourceMapTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { deleteButton.setEnabled(sourceMapTable.getSelectedRow() > -1); } } }); class SourceMapTableCellEditor extends AbstractCellEditor implements TableCellEditor { private JTable table; private int column; private JTextField textField; private Object originalValue; private String newValue; public SourceMapTableCellEditor(JTable table, int column) { super(); this.table = table; this.column = column; textField = new JTextField(); textField.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { textField.setCaretPosition(textField.getText().length()); } }); } @Override public boolean isCellEditable(EventObject evt) { if (evt == null) { return false; } if (evt instanceof MouseEvent) { return ((MouseEvent) evt).getClickCount() >= 2; } return true; } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { originalValue = value; newValue = null; textField.setText(String.valueOf(value)); return textField; } @Override public Object getCellEditorValue() { if (newValue != null) { return newValue; } else { return originalValue; } } @Override public boolean stopCellEditing() { if (!valueChanged()) { super.cancelCellEditing(); } else { newValue = textField.getText(); } return super.stopCellEditing(); } private boolean valueChanged() { String value = textField.getText(); if (StringUtils.isBlank(value)) { return false; } for (int i = 0; i < table.getRowCount(); i++) { Object tableValue = table.getValueAt(i, column); if (tableValue != null && String.valueOf(tableValue).equals(value)) { return false; } } return true; } } sourceMapTable.getColumnModel().getColumn(0).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 0)); sourceMapTable.getColumnModel().getColumn(1).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 1)); sourceMapScrollPane.setViewportView(sourceMapTable); deleteButton.setEnabled(false); }
From source file:de.tor.tribes.ui.views.DSWorkbenchTagFrame.java
@Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { int selectionCount = jTagsTable.getSelectedRowCount(); if (selectionCount != 0) { showInfo(selectionCount + ((selectionCount == 1) ? " Gruppe gewhlt" : " Gruppen gewhlt")); }//w w w. ja v a 2 s .co m updateVillageList(); } }
From source file:de.tor.tribes.ui.views.DSWorkbenchConquersFrame.java
@Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { int selectionCount = jConquersTable.getSelectedRowCount(); if (selectionCount != 0) { showInfo(/* w ww . j a va2s.c o m*/ selectionCount + ((selectionCount == 1) ? " Eroberung gewhlt" : " Eroberungen gewhlt")); } } }
From source file:de.mprengemann.intellij.plugin.androidicons.forms.AndroidBatchScaleImporter.java
private void initRowSelection() { table.getColumnModel().setColumnSelectionAllowed(false); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override/*w w w . j a va 2s.co m*/ public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } int selectedRow = table.getSelectedRow(); if (selectedRow >= 0) { updateImage(tableModel.getItem(selectedRow)); } } }); }
From source file:com.mirth.connect.client.ui.SettingsPanelResources.java
@Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { final int previousSelectedRow = selectedRow; if (previousSelectedRow >= 0) { resetInvalidProperties();//from w w w .j a va 2 s . c om final String errors = checkProperties().trim(); if (StringUtils.isNotEmpty(errors)) { resourceTable.getSelectionModel().removeListSelectionListener(this); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { resourceTable.getSelectionModel().setSelectionInterval(previousSelectedRow, previousSelectedRow); getFrame().alertError(getFrame(), "Error validating resource settings:\n\n" + errors); resourceTable.getSelectionModel().addListSelectionListener(SettingsPanelResources.this); } }); return; } updateResource(previousSelectedRow); } int newSelectedRow = resourceTable.getSelectedRow(); if (newSelectedRow >= 0) { ResourceProperties properties = (ResourceProperties) resourceTable.getModel() .getValueAt(newSelectedRow, PROPERTIES_COLUMN); if (properties instanceof InvalidResourceProperties) { currentPropertiesPanel = null; for (Entry<String, ResourcePropertiesPanel> entry : propertiesPanelMap.entrySet()) { entry.getValue().setVisible(false); } fillerLabel.setText( "The currently selected resource is invalid. Check to make sure all resource extensions are correctly loaded."); fillerPanel.setVisible(true); Throwable cause = ((InvalidResourceProperties) properties).getCause(); if (cause != null) { exceptionScrollPane.setVisible(true); exceptionTextPane.setText(ExceptionUtils.getStackTrace(cause)); exceptionTextPane.setCaretPosition(0); } else { exceptionScrollPane.setVisible(false); } } else { boolean saveEnabled = getFrame().isSaveEnabled(); changePropertiesPanel(properties.getType()); resetInvalidProperties(); currentPropertiesPanel.setProperties(properties); getFrame().setSaveEnabled(saveEnabled); } } else { changePropertiesPanel(null); } selectedRow = newSelectedRow; setVisibleTasks(removeResourceTaskIndex, removeResourceTaskIndex, selectedRow > 0); } }
From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java
@Override public void valueChanged(final ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { // fillRightPartition(); }//from w w w . j ava 2s .co m }
From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java
private void initAuthorsTable() { authorsTable.getColumnModel().getColumn(2) .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy"))); authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() { @Override//from w w w .ja va 2 s . co m public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected, boolean hasFocus, int row, int column) { if (value instanceof Date) { // You could use SimpleDateFormatter instead value = new SimpleDateFormat("dd. MM. yyyy").format(value); } return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column); } }); authorsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ListSelectionModel selectionModel = authorsTable.getSelectionModel(); selectionModel.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { DefaultListSelectionModel source = (DefaultListSelectionModel) e.getSource(); if (source.getMinSelectionIndex() >= 0) { authorsTableModel.setCurrentSlectedIndex(source.getMinSelectionIndex()); } if (!e.getValueIsAdjusting()) { booksTableModel.setAuthorIndex(source.getMinSelectionIndex()); } } }); authorsTable.getColumnModel().getColumn(2) .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy"))); authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected, boolean hasFocus, int row, int column) { if (value instanceof Date) { // You could use SimpleDateFormatter instead value = new SimpleDateFormat("dd. MM. yyyy").format(value); } return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column); } }); JPopupMenu authorsPopupMenu = new JPopupMenu(); JMenuItem deleteItem = new JMenuItem("Delete"); authorsPopupMenu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { int rowAtPoint = authorsTable.rowAtPoint( SwingUtilities.convertPoint(authorsPopupMenu, new Point(0, 0), authorsTable)); if (rowAtPoint > -1) { authorsTable.setRowSelectionInterval(rowAtPoint, rowAtPoint); authorsTableModel.setCurrentSlectedIndex(rowAtPoint); } } }); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // TODO Auto-generated method stub } @Override public void popupMenuCanceled(PopupMenuEvent e) { // TODO Auto-generated method stub } }); deleteItem.addActionListener(new ActionListener() { private Author author; @Override public void actionPerformed(ActionEvent e) { new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { author = authorsTableModel.getAuthors().get(authorsTable.getSelectedRow()); log.debug("Deleting author: " + author.getFirstname() + " " + author.getSurname() + " from database."); authorManager.deleteAuthor(author); return null; } @Override protected void done() { try { get(); } catch (InterruptedException | ExecutionException e) { if (e.getCause() instanceof DataIntegrityViolationException) { JOptionPane.showMessageDialog(MainWindow.this, "Couldn't delete author; there are still some books assigned to him.", "Error", JOptionPane.ERROR_MESSAGE); } log.error("There was an exception thrown during deletion author: " + author.getFirstname() + " " + author.getSurname(), e); return; } updateModel(); } }.execute(); } }); authorsPopupMenu.add(deleteItem); authorsTable.setComponentPopupMenu(authorsPopupMenu); }