/** * Paint one List cell: compute the relevant state, get the "rubber stamp" * cell renderer component, and then use the CellRendererPane to paint it. * Subclasses may want to override this method rather than paint(). * * @see #paint */ private void paintCell(Graphics g, int index) { Object value = getModel().getElementAt(index); boolean cellHasFocus = hasFocus() && (index == getSelectionModel().getLeadSelectionIndex()); boolean isSelected = getSelectionModel().isSelectedIndex(index); Component renderer = getCellRenderer().getListCellRendererComponent( this, value, index, isSelected, cellHasFocus ); renderer.setSize(fixedCellWidth, fixedCellHeight); renderer.paint(g); }
public Component getTableCellRendererComponent(JTable x, Object value, boolean isSelected, boolean hasFocus, int row, int column) { boolean selected = table.getSelectionModel().isSelectedIndex(row); Component component = table.getTableHeader().getDefaultRenderer().getTableCellRendererComponent(table, value, false, false, -1, -2); ((JLabel) component).setHorizontalAlignment(SwingConstants.CENTER);
public boolean isSelectedIndex(final int pIndex) { if (pIndex == -1) { return false; } return mListSelectionModel.isSelectedIndex(pIndex); }
public boolean isSelectedIndex(final int pIndex) { if (pIndex == -1) { return false; } return mListSelectionModel.isSelectedIndex(pIndex); }
public boolean isSelectedIndex(final int pIndex) { //noinspection SimplifiableIfStatement if (pIndex == -1) return false; else return mListSelectionModel.isSelectedIndex(pIndex); }
protected boolean[] getStates(int selectedIndex) { int max = model.getSize(); if (_states == null || _states.length != max) { _states = new boolean[max]; } else { Arrays.fill(_states, false); } for (int i = 0; i < max; i++) { _states[i] = i != selectedIndex && delegate.isSelectedIndex(i); } return _states; }
protected boolean[] getStates(int selectedIndex) { int max = model.getSize(); if (_states == null || _states.length != max) { _states = new boolean[max]; } else { Arrays.fill(_states, false); } for (int i = 0; i < max; i++) { _states[i] = i != selectedIndex && delegate.isSelectedIndex(i); } return _states; }
private void toggleSelection(int index){ if(index<0) return; if(selectionModel.isSelectedIndex(index)){ selectionModel.removeSelectionInterval(index, index);} else { selectionModel.addSelectionInterval(index, index);} }
@Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component component = super.prepareRenderer(renderer, row, column); // if the rendere is a JComponent and the given row isn't part of a // selection, make the renderer non-opaque so that striped rows show // through. if (component instanceof JComponent) { ((JComponent) component).setOpaque(getSelectionModel().isSelectedIndex(row)); } return component; }
public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; ListSelectionModel lm = (ListSelectionModel) e.getSource(); for (int i = e.getFirstIndex(); i <= e.getLastIndex(); i++) { if (lm.isSelectedIndex(i)) { m_PanelAttributeSummary.setAttribute(i); break; } } } });
public void mouseClicked( final MouseEvent e ) { if ( e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2 ) { final ArrayTableModel data = getTableModel(); final ArrayTableModel fields = getPaletteListModel(); for ( int i = 0; i < fields.getSize(); i++ ) { if ( selectionModel.isSelectedIndex( i ) ) { data.add( fields.get( i ) ); } } } } }
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus){ Component renderer = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); checkBox.setSelected(selectionModel.isSelectedIndex(index)); removeAll(); add(checkBox, BorderLayout.WEST); add(renderer, BorderLayout.CENTER); return this; } }
public Component getListCellRendererComponent( final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus ) { final Component renderer = _delegate.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus ); _checkBox.setSelected( _selectionModel.isSelectedIndex( index ) ); removeAll(); add( _checkBox, BorderLayout.WEST ); add( renderer, BorderLayout.CENTER ); return this; } }
public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; ListSelectionModel lm = (ListSelectionModel) e.getSource(); for (int i = e.getFirstIndex(); i <= e.getLastIndex(); i++) { if (lm.isSelectedIndex(i)) { m_PanelAttributeSummary.setAttribute(i); break; } } } });
protected ListSelectionModel saveRowsSelection() { ListSelectionModel savedSelection = new DefaultListSelectionModel(); for (int viewRowIndex = rowsSelectionModel.getMinSelectionIndex(); viewRowIndex <= rowsSelectionModel.getMaxSelectionIndex(); viewRowIndex++) { if (rowsSelectionModel.isSelectedIndex(viewRowIndex)) { // We have to act upon view coordinates here! savedSelection.addSelectionInterval(viewRowIndex, viewRowIndex); } } return savedSelection; }
protected ListSelectionModel saveColumnsSelection() { ListSelectionModel savedSelection = new DefaultListSelectionModel(); for (int viewColumnIndex = columnsSelectionModel.getMinSelectionIndex(); viewColumnIndex <= columnsSelectionModel.getMaxSelectionIndex(); viewColumnIndex++) { if (columnsSelectionModel.isSelectedIndex(viewColumnIndex)) { // We have to act upon view coordinates here! savedSelection.addSelectionInterval(viewColumnIndex, viewColumnIndex); } } return savedSelection; }
public ListSelectionModel saveSelection() { ListSelectionModel cacheSelection = new DefaultListSelectionModel(); if (viewSelection != null) { for (int irow = viewSelection.getMinSelectionIndex(); irow <= viewSelection.getMaxSelectionIndex(); irow++) { if (viewSelection.isSelectedIndex(irow)) { int modelRow = convertRowIndexToModel(irow); cacheSelection.addSelectionInterval(modelRow, modelRow); } } } return cacheSelection; }
@SuppressWarnings("PMD.UnusedFormalParameter") private void invertSelectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_invertSelectionButtonActionPerformed for (int i = 0; i < this.mainListModel.getRowCount(); i++) { if (this.mainListSelectionModel.isSelectedIndex(i)) { this.mainListSelectionModel.removeIndexInterval(i, i); } else { this.mainListSelectionModel.addSelectionInterval(i, i); } } this.mainListModel.fireTableDataChanged(); this.updateRowHeights(); }//GEN-LAST:event_invertSelectionButtonActionPerformed
private static Object getSelectedElement(JList list) { assert list != null; // PENDING(shannonh) - more cases to consider int index = list.getSelectionModel().getLeadSelectionIndex(); index = list.getSelectionModel().isSelectedIndex(index) ? index : list.getSelectionModel().getMinSelectionIndex(); if (index == -1) { return null; } return getElement(list, index); }
private static Object getSelectedElement(JList list) { assert list != null; // PENDING(shannonh) - more cases to consider int index = list.getSelectionModel().getLeadSelectionIndex(); index = list.getSelectionModel().isSelectedIndex(index) ? index : list.getSelectionModel() .getMinSelectionIndex(); if (index == -1) { return null; } return getElement(list, index); }