@Override public Table<?> toTable(JGrid grid) { ListSelectionModel r = grid.getSelectionModel(); ListSelectionModel c = grid.getColumnModel().getSelectionModel(); return !r.isSelectionEmpty() && !c.isSelectionEmpty() ? copy2( grid.getModel(), Range.closed(r.getMinSelectionIndex(), r.getMaxSelectionIndex()), Range.closed(c.getMinSelectionIndex(), c.getMaxSelectionIndex()), rowHeader, columnHeader) : new Table<>(0, 0); }
private Component create() { JPanel result = new JPanel(new BorderLayout()); final DynamicModel model = new DynamicModel(); final JSpinField rowCount = new JSpinField(0, 1000); rowCount.setValue(model.getRowCount()); rowCount.addPropertyChangeListener( SwingProperties.SPIN_FIELD_VALUE_PROPERTY, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { model.setRowCount(rowCount.getValue()); } }); final JSpinField colCount = new JSpinField(0, 1000); colCount.setValue(model.getColumnCount()); colCount.addPropertyChangeListener( SwingProperties.SPIN_FIELD_VALUE_PROPERTY, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { model.setColCount(colCount.getValue()); } }); JPanel north = new JPanel(new FlowLayout()); north.add(new JLabel("RowCount:")); north.add(rowCount); north.add(new JLabel("ColCount:")); north.add(colCount); north.setBorder((Border) UIManager.get("Nb.Editor.Toolbar.border")); result.add(north, BorderLayout.NORTH); JGrid grid = new JGrid(); grid.setModel(model); grid.setNoDataRenderer(new XTable.DefaultNoDataRenderer("Drag anything here")); grid.setRowSelectionAllowed(true); grid.setColumnSelectionAllowed(true); grid.setTransferHandler( new TransferHandler() { Random r = new Random(); @Override public boolean canImport(TransferHandler.TransferSupport support) { return true; } @Override public boolean importData(TransferHandler.TransferSupport support) { model.setColCount(r.nextInt(10)); model.setRowCount(r.nextInt(10)); return true; } }); result.add(grid, BorderLayout.CENTER); return result; }
@Override public Table<?> toTable(JGrid grid) { GridModel model = grid.getModel(); return copy2(model, Range.<Integer>all(), Range.<Integer>all(), rowHeader, columnHeader); }
@Override public Table<?> toTable(JGrid grid) { return copy2(grid.getModel(), rowRange, columnRange, rowHeader, columnHeader); }