JTable - Programmatically selection multiple cells

Hi!
I'd like to know wether it's possible to programmatically select certain cells of a Jtable component.
For example:
My Jtable looks like that
1 2 3
4 5 6
7 8 9
and I want to select cell 2,4 and 7. How could I do that??
Thanks for answers...

Hello,
I consciously read your thread, but I still can't get the sample code running.
(java.lang.StackOverflowError
Exception in thread "main" )
Would you please give me a hint?
Or better,
send or post me the sample code of your class 'AttributiveCellTableModel', please.
Thank you very much in advance!
Thorsten

Similar Messages

  • Programmatically selecting a cell in a two-dimensional JTable

    The problem is that when a person edits a cell and the value fails validation, I would like to programmatically select the cell. The validation is done in the setValueAt method of a Class extending the AbstractTableModel. By simply returning out of that method, the cell value is set back to the way it was before the user changed it. In addition, I would like the problem cell to be automatically selected rather than requiring the user to click in it to select it. The first question is 1- Is this possible, and 2- Any clues as to how to select it?
    We find for examle in Chapter 6 of the CoreJava 2 Vol II Advanced features statements like this on page 399 of, I think, Edition 4, (can anyone tell what edition it is?) by Cay Horstmann
    void setCellSelectionEnabled(boolean b)
    If b is true, then individual cells are selected (when the user clicks in the cell?). I have researched this problem for several days and don't have a clue how to automatically select the cell although I know precisely what row and column it is.

    This is the code to return the focus to error cell.
    /* TableCellValidator class */
    /* The class basically validates the input entry in a cell and */
    /* pops up a JOptionPane if its an invalid input */
    /* And an OK is clicked on the JOptionPane, the control returns back */
    /* to the same cell */
    /* Basic Idea: The controls Arrow/Tab/mouse clicks are handled by our */
    /* ----------- custom table. Its has been slightly tricky to handle */
    /* mouse clicks, since when you click the next cell, the */
    /* editingrow/editingcol advances. Hence the */
    /* previousrow/previouscol has been captured in the */
    /* setValueAt method. */
    /* To capture Table/Arrow/Numeric Arrow, The keyStrokes(TAB etc)*/
    /* assigned different AbstractionActions to execute like */
    /* validateBeforeTabbingToNextCell */
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableCellValidator {
    * Constructor.
    * Basically instantiates the class and sets up the
    * JFrame object and the table.
    public TableCellValidator() {
    JFrame f = new JFrame("JTable test");
    f.getContentPane().add(new JScrollPane(createTable()), "Center");
    f.pack();
    f.setVisible(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    * A method which created our custom table.
    * The JTable methods processMouseEvent
    * and setValueAt are overridden to handle
    * Mouseclicks.
    * The Tables ActionMap is fed with different
    * AbstractAction classes eg: (validateBeforeTabbingToNextCell)
    * (Scroll down below for the innerclass
    * validateBeforeTabbingToNextCell).
    * So basically when TAB is pressed the stuff present
    * in the validateBeforeTabbingToNextCell's actionPerformed(..)
    * method is performed.
    * So we need to handle all the stuff a TAB does.
    * ie. if a TAB hits the end of the row, we need to increment
    * it to the next Row (if the validation is successful)
    * in the current row etc..
    * @return JTable
    * @see validateBeforeTabbingToNextCell
    * @see validateBeforeShiftTabbingToNextCell
    * @see validateBeforeMovingToNextCell
    * @see validateBeforeMovingDownToCell
    * @see validateBeforeMovingUpToCell
    * @see validateBeforeMovingLeftToCell
    private JTable createTable() {
    JTable table = new JTable(createModel()){
    private int previousRow =0;
    private int previousCol =0;
    * Processes mouse events occurring on this component by
    * dispatching them to any registered
    * <code>MouseListener</code> objects.
    * <p>
    * This method is not called unless mouse events are
    * enabled for this component. Mouse events are enabled
    * when one of the following occurs:
    * <p><ul>
    * <li>A <code>MouseListener</code> object is registered
    * via <code>addMouseListener</code>.
    * </ul>
    * <p>Note that if the event parameter is <code>null</code>
    * the behavior is unspecified and may result in an
    * exception.
    * @param e the mouse event
    * @see java.awt.event.MouseEvent
    * @see java.awt.event.MouseListener
    * @see #addMouseListener
    * @see #enableEvents
    * @since JDK1.1
    protected void processMouseEvent(MouseEvent e) {
    boolean canMoveFocus = true;
    int currentRowAndColumn[] = getCurrentRowAndColumn(this); //we pull the current row and column
    int row = currentRowAndColumn[0];
    int column = currentRowAndColumn[1];
    if ( e.getID() == MouseEvent.MOUSE_PRESSED || e.getID() == MouseEvent.MOUSE_CLICKED) {
    stopCurrentCellBeingEdited(this); //stop the cellbeing edited to grab its value
    final String value = (String)getModel().getValueAt(row,column);
    try {
    Integer.parseInt(value);
    } catch (NumberFormatException nfe) {
    SwingUtilities.invokeLater(new Runnable(){
    public void run() {
    JOptionPane.showMessageDialog(null,"Alpha value ="+ value ,"Invalid entry!",JOptionPane.WARNING_MESSAGE);
    changeSelection(previousRow,previousCol, true, true);
    editCellAt(previousRow, previousCol);
    requestFocus(); // or t.getEditorCompo
    if ( canMoveFocus ) {
    super.processMouseEvent(e);
    * The method setValueAt of the JTable is overridden
    * to save the previousRow/previousCol to enable us to
    * get back to the error cell when a Mouse is clicked.
    * This is circumvent the problem, when a mouse is clicked in
    * a different cell, the control goes to that cell and
    * when you ask for getEditingRow , it returns the row that
    * the current mouse click occurred. But we need a way
    * to stop at the previous cell(ie. the cell that we were editing
    * before the mouse click occurred) when an invalid data has
    * been entered and return the focus to that cell
    * @param aValue
    * @param row
    * @param col
    public void setValueAt(Object aValue,int row, int col) {     
    this.previousRow = row;
    this.previousCol = col;
    super.setValueAt(aValue,row,col);
    /* These are the various KeyStrokes like
    ENTER,SHIFT-TAB,TAB,Arrow Keys,Numeric Arrow keys being assigned an Abstract action (key string ) in to the
    inputMap first . Then an Action is assigned in the ActionMap object
    table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0) ,"validateBeforeTabbingToNextCell");
    table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,1) ,"validateBeforeShiftTabbingToNextCell");
    table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,0) ,"validateBeforeMovingToNextCell");
    table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT,0) ,"validateBeforeMovingToNextCell");
    table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,0) ,"validateBeforeMovingDownToCell");
    table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_DOWN,0) ,"validateBeforeMovingDownToCell");
    table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0) ,"validateBeforeMovingDownToCell");
    table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP,0) ,"validateBeforeMovingUpToCell");
    table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_UP,0) ,"validateBeforeMovingUpToCell");
    table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,0) ,"validateBeforeMovingLeftToCell");
    table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT,0) ,"validateBeforeMovingLeftToCell");
    table.getActionMap().put("validateBeforeTabbingToNextCell",
    new validateBeforeTabbingToNextCell());
    table.getActionMap().put("validateBeforeShiftTabbingToNextCell",
    new validateBeforeShiftTabbingToNextCell());
    table.getActionMap().put("validateBeforeMovingToNextCell",
    new validateBeforeMovingToNextCell());
    table.getActionMap().put("validateBeforeMovingDownToCell",
    new validateBeforeMovingDownToCell());
    table.getActionMap().put("validateBeforeMovingUpToCell",
    new validateBeforeMovingUpToCell());
    table.getActionMap().put("validateBeforeMovingLeftToCell",
    new validateBeforeMovingLeftToCell());
    table.setPreferredScrollableViewportSize(table.getPreferredSize());
    return table;
    * A table model is created here for 5 rows/5 columns.
    * And the isCellEditable is overridden to return true,
    * indicating that the cell can be edited.
    * So fine tuned control can be done here by saying,
    * the user can be allowed to edit Row 1,3 or 5 only.
    * or column 1 only etc..
    * @return DefaultTableModel
    private DefaultTableModel createModel() {
    DefaultTableModel model = new DefaultTableModel(5, 5) {
    public boolean isCellEditable(int row, int column) {
    return true;
    return model;
    * This method basically returns the currentRow/currentCol value
    * If the current Row/Col is being edited then
    * it returns the getEditingRow/getEditingColumn
    * If its not being edited,
    * it return the getAnchorSelectionIndex of the JTables
    * ListSelectionModel.
    * If the column or row is -1, then it return 0.
    * The first element in the int[] array is the row
    * The second element in the int[] array is the column
    * @param t input a JTable
    * @return int[]
    * @see ListSelectionModel
    * @see JTable
    private int[] getCurrentRowAndColumn(JTable t){
    int[] currentRowAndColum = new int[2];
    int row, column;
    if (t.isEditing()) {
    row = t.getEditingRow();
    column = t.getEditingColumn();
    } else {
    row = t.getSelectionModel().getAnchorSelectionIndex();
    if (row == -1) {
    if (t.getRowCount() == 0) {
    //actually this should never happen.. we need to return an exception
    return null;
    column =t.getColumnModel().getSelectionModel().getAnchorSelectionIndex();
    if (column == -1) {
    if (t.getColumnCount() == 0) {
    //actually this should never happen.. we need to return an exception
    return null;
    column = 0;
    currentRowAndColum[0]=row;
    currentRowAndColum[1]=column;
    return currentRowAndColum;
    * Tbis basically a wrapper method for CellEditors,
    * stopCellEditing method.
    * We need to do this because,
    * for instance we have entered a value in Cell[0,0] as 3
    * and when we press TAB or mouse click or any other relevant
    * navigation keys,
    * ** IF the cell is BEING EDITED,
    * when we do a getValueAt(cellrow,cellcol) at the TableModel
    * level , it would return "null". To overcome this problem,
    * we tell the cellEditor to stop what its doing. and then
    * when you do a getValueAt[cellrow,cellcol] it would
    * return us the current cells value
    * @param t Input a JTable
    * @see CellEditor
    private void stopCurrentCellBeingEdited(JTable t){
    CellEditor ce = t.getCellEditor(); /*this not the ideal way to do..
    since there is no way the CellEditor could be null.
    But a nullpointer arises when trying to work with mouse.. rather than just
    keyboard" */
    if (ce!=null) {
    ce.stopCellEditing();
    * The following Action class handles when a
    * RIGHT ARROW or NUMERIC RIGHT ARROW is pressed.
    * There just a basic checking for Numeric values
    * (Integer.parseInt) inside the code.
    * When validation is successfull, we need to move it to the
    * next Cell.. else take it back to the currentCell
    class validateBeforeMovingToNextCell extends AbstractAction {
    * The following Action class handles when a
    * DOWN ARROW or NUMERIC DOWN ARROW is pressed.
    * There is just a basic checking for Numeric values
    * (Integer.parseInt) inside the code.
    * When validation is successfull, we need to move it to
    * down by one Cell.. else take it back to the currentCell
    * @param e
    public void actionPerformed(ActionEvent e) {
    JTable t = (JTable) e.getSource();
    int currentRowAndColumn[] = getCurrentRowAndColumn(t);
    int row = currentRowAndColumn[0];
    int column = currentRowAndColumn[1];
    stopCurrentCellBeingEdited(t);
    String value = (String)t.getModel().getValueAt(row,column);
    if (value!= null && !value.equals("")) {
    try {
    Integer.parseInt(value);
    } catch (NumberFormatException nfe) {
    JOptionPane.showMessageDialog(null,"Please input numeric values at cell[row="+row+","+"col="+column+"]","Invalid Input!!",JOptionPane.WARNING_MESSAGE);
    t.changeSelection(row, column, true, true);
    t.editCellAt(row,column);
    t.getEditorComponent().requestFocus();
    return;
    column++;
    if (column >= t.getColumnCount())
    column = column-1;
    if (t.isCellEditable(row, column)) {
    t.changeSelection(row, column, true, true);
    t.editCellAt(row, column);
    if ((t.getEditingRow() == row)
    && (t.getEditingColumn() == column)) {
    t.requestFocus();
    return;
    * The following Action class handles when a
    * DOWN ARROW or NUMERIC DOWN ARROW is pressed.
    * There just a basic checking for Numeric values
    * (Integer.parseInt) inside the code.
    * When validation is successfull, we need to move it to the
    * down by Cell.. else take it back to the currentCell
    class validateBeforeMovingDownToCell extends AbstractAction {
    public void actionPerformed(ActionEvent e) {
    JTable t = (JTable) e.getSource();
    int currentRowAndColumn[] = getCurrentRowAndColumn(t);
    int row = currentRowAndColumn[0];
    int column = currentRowAndColumn[1];
    stopCurrentCellBeingEdited(t);
    String value = (String)t.getModel().getValueAt(row,column);
    if (value!= null && !value.equals("")) {
    try {
    Integer.parseInt(value);
    } catch (NumberFormatException nfe) {
    JOptionPane.showMessageDialog(null,"Please input numeric values at cell[row="+row+","+"col="+column+"]","Invalid Input!!",JOptionPane.WARNING_MESSAGE);
    t.changeSelection(row, column, true, true);
    t.editCellAt(row,column);
    t.getEditorComponent().requestFocus();
    return;
    row++;
    if (row >= t.getRowCount())
    row = row - 1;
    if (t.isCellEditable(row, column)) {
    t.changeSelection(row, column, true, true);
    t.editCellAt(row, column);
    if ((t.getEditingRow() == row)
    && (t.getEditingColumn() == column)) {
    t.requestFocus();
    return;
    * The following Action class handles when a
    * UP ARROW or NUMERIC UP ARROW is pressed.
    * There just a basic checking for Numeric values
    * (Integer.parseInt) inside the code.
    * When validation is successfull, we need to move the cursor/
    * editable status up by a Cell.. else take it back to the currentCell
    class validateBeforeMovingUpToCell extends AbstractAction {
    public void actionPerformed(ActionEvent e) {
    JTable t = (JTable) e.getSource();
    int currentRowAndColumn[] = getCurrentRowAndColumn(t);
    int row = currentRowAndColumn[0];
    int column = currentRowAndColumn[1];
    stopCurrentCellBeingEdited(t);
    String value = (String)t.getModel().getValueAt(row,column);
    if (value!= null && !value.equals("")) {
    try {
    Integer.parseInt(value);
    } catch (NumberFormatException nfe) {
    JOptionPane.showMessageDialog(null,"Please input numeric values at cell[row="+row+","+"col="+column+"]","Invalid Input!!",JOptionPane.WARNING_MESSAGE);
    t.changeSelection(row, column, true, true);
    t.editCellAt(row,column);
    t.getEditorComponent().requestFocus();
    return;
    row--;
    if (row <0)
    row = 0;
    if (t.isCellEditable(row, column)) {
    t.changeSelection(row, column, true, true);
    t.editCellAt(row, column);
    if ((t.getEditingRow() == row)
    && (t.getEditingColumn() == column)) {
    t.requestFocus();
    return;
    * The following Action class handles when a
    * LEFT ARROW or NUMERIC LEFT ARROW is pressed.
    * There just a basic checking for Numeric values
    * (Integer.parseInt) inside the code.
    * When validation is successfull, we need to move the cursor/
    * editable status up by a Cell.. else take it back to the currentCell
    class validateBeforeMovingLeftToCell extends AbstractAction {
    public void actionPerformed(ActionEvent e) {
    JTable t = (JTable) e.getSource();
    int currentRowAndColumn[] = getCurrentRowAndColumn(t);
    int row = currentRowAndColumn[0];
    int column = currentRowAndColumn[1];
    stopCurrentCellBeingEdited(t);
    String value = (String)t.getModel().getValueAt(row,column);
    if (value!= null && !value.equals("")) {
    try {
    Integer.parseInt(value);
    } catch (NumberFormatException nfe) {
    JOptionPane.showMessageDialog(null,"Please input numeric values at cell[row="+row+","+"col="+column+"]","Invalid Input!!",JOptionPane.WARNING_MESSAGE);
    t.changeSelection(row, column, true, true);
    t.editCellAt(row,column);
    t.getEditorComponent().requestFocus();
    return;
    column--;
    if (column <0)
    column = 0;
    if (t.isCellEditable(row, column)) {
    t.changeSelection(row, column, true, true);
    t.editCellAt(row, column);
    if ((t.getEditingRow() == row)
    && (t.getEditingColumn() == column)) {
    t.requestFocus();
    return;
    * The following Action class handles when a TAB is pressed.
    * There just a basic checking for Numeric values
    * (Integer.parseInt) inside the code.
    * When validation is successfull, we need to move the cursor/
    * editable status up by a Cell.. else take it back to the currentCell
    class validateBeforeTabbingToNextCell extends AbstractAction {
    public void actionPerformed(ActionEvent e) {
    JTable t = (JTable) e.getSource();
    int currentRowAndColumn[] = getCurrentRowAndColumn(t);
    int row = currentRowAndColumn[0];
    int column = currentRowAndColumn[1];
    stopCurrentCellBeingEdited(t);
    String value = (String)t.getModel().getValueAt(row,column);
    if (value!= null && !value.equals("")) {
    try {
    Integer.parseInt(value);
    } catch (NumberFormatException nfe) {
    JOptionPane.showMessageDialog(null,"Please input numeric values at cell[row="+row+","+"col="+column+"]","Invalid Input!!",JOptionPane.WARNING_MESSAGE);
    t.changeSelection(row, column, true, true);
    t.editCellAt(row,column);
    t.getEditorComponent().requestFocus();
    return;
    column++;
    int rows = t.getRowCount(), columns = t.getColumnCount();
    while (row < rows) {
    while (column < columns) {
    if (t.isCellEditable(row, column)) {
    t.changeSelection(row, column, true, true);
    t.editCellAt(row, column);
    if ((t.getEditingRow() == row)
    && (t.getEditingColumn() == column)) {
    t.requestFocus();
    return;
    column++;
    row++;
    column = 0;
    row = 0;
    if (t.isCellEditable(row, column)) {
    t.changeSelection(row, column, true, true);
    t.editCellAt(row, column);
    if ((t.getEditingRow() == row)
    && (t.getEditingColumn() == column)) {
    t.requestFocus();
    return;
    * The following Action class handles when a SHIFT TAB is pressed.
    * There just a basic checking for Numeric values
    * (Integer.parseInt) inside the code.
    * When validation is successfull, we need to move the cursor/
    * editable status up by a Cell.. else take it back to the currentCell
    class validateBeforeShiftTabbingToNextCell extends AbstractAction {
    public void actionPerformed(ActionEvent e) {
    JTable t = (JTable) e.getSource();
    int currentRowAndColumn[] = getCurrentRowAndColumn(t);
    int row = currentRowAndColumn[0];
    int column = currentRowAndColumn[1];
    stopCurrentCellBeingEdited(t);
    String value = (String)t.getModel().getValueAt(row,column);
    if (value!= null && !value.equals("")) {
    try {
    Integer.parseInt(value);
    } catch (NumberFormatException nfe) {
    JOptionPane.showMessageDialog(null,"Please input numeric values at cell[row="+row+","+"col="+column+"]","Invalid Input!!",JOptionPane.WARNING_MESSAGE);
    t.changeSelection(row, column, true, true);
    t.editCellAt(row,column);
    t.getEditorComponent().requestFocus();
    return;
    column--;
    int rows = t.getRowCount(), columns = t.getColumnCount();
    while ((row < rows) && (row >= 0)) {
    while ((column < columns) && (column >= 0)) {
    if (t.isCellEditable(row, column)) {
    t.changeSelection(row, column, true, true);
    t.editCellAt(row, column);
    if ((t.getEditingRow() == row)
    && (t.getEditingColumn() == column)) {
    t.requestFocus();
    return;
    column--;
    row--;
    column = columns - 1;
    row = rows - 1;
    if (t.isCellEditable(row, column)) {
    t.changeSelection(row, column, true, true);
    t.editCellAt(row, column);
    if ((t.getEditingRow() == row)
    && (t.getEditingColumn() == column)) {
    t.requestFocus();
    return;
    public static void main(String[] args) {
    new TableCellValidator();

  • How can I select multiple cells in tableview with javafx only by mouse?

    I have an application with a tableview in javafx and i want to select multiple cells only by mouse (something like the selection which exists in excel).I tried with setOnMouseDragged but i cant'n do something because the selection returns only the cell from where the selection started.Can someone help me?

    For mouse drag events to propagate to nodes other than the node in which the drag initiated, you need to activate a "full press-drag-release gesture" by calling startFullDrag(...) on the initial node. (See the Javadocs for MouseEvent and MouseDragEvent for details.) Then you can register for MouseDragEvents on the table cells in order to receive and process those events.
    Here's a simple example: the UI is not supposed to be ideal but it will give you the idea.
    import java.util.Arrays;
    import javafx.application.Application;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.SelectionMode;
    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.input.MouseDragEvent;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.VBox;
    import javafx.scene.text.Font;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    public class DragSelectionTable extends Application {
        private TableView<Person> table = new TableView<Person>();
        private final ObservableList<Person> data =
            FXCollections.observableArrayList(
                new Person("Jacob", "Smith", "[email protected]"),
                new Person("Isabella", "Johnson", "[email protected]"),
                new Person("Ethan", "Williams", "[email protected]"),
                new Person("Emma", "Jones", "[email protected]"),
                new Person("Michael", "Brown", "[email protected]")
        public static void main(String[] args) {
            launch(args);
        @Override
        public void start(Stage stage) {
            Scene scene = new Scene(new Group());
            stage.setTitle("Table View Sample");
            stage.setWidth(450);
            stage.setHeight(500);
            final Label label = new Label("Address Book");
            label.setFont(new Font("Arial", 20));
            table.setEditable(true);
            TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
            firstNameCol.setMinWidth(100);
            firstNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("firstName"));
            TableColumn<Person, String> lastNameCol = new TableColumn<>("Last Name");
            lastNameCol.setMinWidth(100);
            lastNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("lastName"));
            TableColumn<Person, String> emailCol = new TableColumn<>("Email");
            emailCol.setMinWidth(200);
            emailCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("email"));
            final Callback<TableColumn<Person, String>, TableCell<Person, String>> cellFactory = new DragSelectionCellFactory();
            firstNameCol.setCellFactory(cellFactory);
            lastNameCol.setCellFactory(cellFactory);
            emailCol.setCellFactory(cellFactory);
            table.setItems(data);
            table.getColumns().addAll(Arrays.asList(firstNameCol, lastNameCol, emailCol));
            table.getSelectionModel().setCellSelectionEnabled(true);
            table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
            final VBox vbox = new VBox();
            vbox.setSpacing(5);
            vbox.setPadding(new Insets(10, 0, 0, 10));
            vbox.getChildren().addAll(label, table);
            ((Group) scene.getRoot()).getChildren().addAll(vbox);
            stage.setScene(scene);
            stage.show();
        public static class DragSelectionCell extends TableCell<Person, String> {
            public DragSelectionCell() {
                setOnDragDetected(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        startFullDrag();
                        getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
                setOnMouseDragEntered(new EventHandler<MouseDragEvent>() {
                    @Override
                    public void handle(MouseDragEvent event) {
                        getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) {
                    setText(null);
                } else {
                    setText(item);
        public static class DragSelectionCellFactory implements Callback<TableColumn<Person, String>, TableCell<Person, String>> {
            @Override
            public TableCell<Person, String> call(final TableColumn<Person, String> col) {         
                return new DragSelectionCell();
        public static class Person {
            private final SimpleStringProperty firstName;
            private final SimpleStringProperty lastName;
            private final SimpleStringProperty email;
            private Person(String fName, String lName, String email) {
                this.firstName = new SimpleStringProperty(fName);
                this.lastName = new SimpleStringProperty(lName);
                this.email = new SimpleStringProperty(email);
            public String getFirstName() {
                return firstName.get();
            public void setFirstName(String fName) {
                firstName.set(fName);
            public String getLastName() {
                return lastName.get();
            public void setLastName(String fName) {
                lastName.set(fName);
            public String getEmail() {
                return email.get();
            public void setEmail(String fName) {
                email.set(fName);

  • How do i select multiple cells in numbers or iPad?

    Hello,
    can you help me? I do not find out how to select multiple cells in a table that do not stand next to each other.
    For example, I want to select cells A1, A3, A9 and so on. Afterwards I want to change the colour.
    Do you have an idea? Perhaps it's quite simple but I don't find the solution
    Sorry, I'm no native english speaker. I hope you'll understand what I am looking for.

    HI Ritscho
    I do not beleive this is possible, I can see other threads here from 2 years ago asking the same thing and none of them have answers.
    You can selesct a range of adjacent cells as Eric said, but not 2 different ranges. I usually use numbers on the iPad for filling in template spreadsheets that I create on my Mac. Most of the formatting I do on the Mac then fill in the blanks whilst i'm out and about.
    Not the answer you were looking for but hope it helps.

  • How do i select multiple cells in dreamweaver cc?

    Can't get cursor to appear to break and merge table cells. Keeps moving entire cell.
    Thanks,
    winifred

    in past version of dreamweaver I could see the cells and borders in design view and easily select multiples with a cursor. Just updated to CC and now only see blue boxes, arrow.
    Any thoughts on how to get a normal table view where I can select back.
    Any help is appreciated.
    winifred

  • Selecting multiple cells with keyboard command?

    Is there a way in Numbers to select many adjecent cells in a column without using the mouse? I have a document that has thousands of rows, so selecting 2000 cells in a column with the mouse for example, obviously takes forever. I would love to be able to give the command 'select A1 to A2000'

    Hi Jerry,
    I didn't want to select the full column, only part of it, like 2000 cells somewhere in the middle of 4000. But your tip made me play around with the Command and Shift keys and I figured out a way to do it. I selcted the full column, then I Command-clicked on the first cell I wanted to in my selection. That made a 'gap' in the selction. Now I went to the very top of the document and Shift-clicked on the first cell. Then all the cells above my first target cell was de-selected. Then I did the same thing and Command-clikced on the the last cell I wanted to highlight, and then went to the last cell of the document and used Shift-Click do deselect everything below the last cell I wanted to select.

  • Formula entry by selecting multiple cells

    I'm in my 30 day eval of iwork. In Numbers I don't see a way of entering a formula without spelling out the cell references into the cell containing the formula result.
    For example, in Excel, after selecting the cell for the result, in that cell I start the formula (=), then I select the first cell, then an operator , then the next cell, then another operator , etc., press enter, then the cell shows the result of the formula (sum in this example).
    The Numbers user manual did not offer a similar alternative. Is there a way to click on each cell reference to build the formula?
    Thanks much

    It seems that you didn't search carefully in the Users Guide.
    Page 89 everybody may read:
    +Adding Cell References to a Formula+
    +To insert a cell reference, _you can click a cell_, click a reference tab, or select a range of+
    +cells when there’s an insertion point in the text field of the Formula Editor or the+
    +Formula Bar. You can also insert a cell reference by typing it.+
    +When you insert a cell reference by selecting cells or reference tabs, Numbers adds cell+
    +references that use header cell names if “Use header cell names as references” is+
    +selected in the General pane of Numbers preferences.+
    +When you type a cell reference that includes the name of a header cell, table, or sheet,+
    +Numbers displays a list of suggestions that match what you’ve started to type. You can+
    +select from the list or continue typing.+
    Yvan KOENIG (from FRANCE samedi 19 juillet 2008 10:02:41)

  • Select Multiple cell

    HI experts,
         It‘s  possible to select Discontinuous cells in OO ALV report ? Like the picture in the attachment,  I want select all the cell in red box.

    Hi
    Please refer this link
    Selecting Cells, Rows and Columns (SAP Library - ALV Object Model
    Regards
    Arun VS

  • JTable: selecting multiple cells

    Supposing you have a spreadsheet layout with A,B,C on the columns and 1,2,3 on the rows, is it possible to allow the user to select cells A1 and C3, like they can in a normal spreadsheet app?
    Somehow I need to obtain this kind of functionality from our system, although I have no idea how at present.

    Something like.....
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TableExample extends JFrame {
       boolean[][] selectedCells = new boolean[5][5];
        public TableExample() {
           super("Table Selection Test");
           final JTable table = new JTable(5, 5) {
              public boolean isCellSelected(int row, int column) {
                 return selectedCells[row][column];
           table.addMouseListener(new MouseAdapter() {
              public void mousePressed(MouseEvent e) {
                 int row = table.rowAtPoint(e.getPoint());
                 int column = table.columnAtPoint(e.getPoint());
                 if (e.isControlDown()) {
                    selectedCells[row][column] = !selectedCells[row][column];
                 else {
                    for (int i = 0 ; i < 5 ; i++) {
                       for (int j = 0 ; j < 5 ; j++) {
                          selectedCells[i][j] = false;
                    selectedCells[row][column] = true;
                 table.repaint();
          getContentPane().setLayout(new BorderLayout());
          getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize(400, 400);
       public static void main(String[] args) {
          new TableExample().setVisible(true);
    }

  • Programmatically select a cell on pivotTable

    Hi,
    I have a case where on initial load of a page that contains a pivot table with dates as columns, on the first row, the current day cell should be selected .
    Pivottable has a selection property accepting oracle.adf.view.faces.bi.component.pivotTable.Selection but I can’t find how to instantiate and set a proper Selection object.
    There are many examples for how to handle similar scenario using table component but nothing for pivot and the documentation is very limited.
    Any help for achieving the desired functionality would be very appreciated.
    Yiannis

    Any help ?

  • How to select multiple cells on a spreadsheet (online diary) without click and drag or shift and arrow keys as iPad has neither :(

    Hey guys really annoyed as I got my I pad with main reason of being able to update my online diary which is basically a spreadsheet, but I can't select more than one cell to book out a time slot, dragging just tees up the copy function and without arrow keys cannot shift and highlight, coming from windows wandering if this function is done another way on macs?  Any help would be appreciated as I'm thinking only way is to get the wireless keyboard which has arrow keys but kind of defeats the point of iPad.
    Thanks in advance ;)

    I guess I should state how much of a newbie I am.
    I did take a summer Java course at a community college this summer and I have some other programming experience (mostly Matlab).
    The course covered a lot of the language but it wasn't exhaustive. We covered (in no particular order) Arrays, Interfaces, overloading, inheritance, loops, actionlisteners, Layout managers, exceptions (a little) One thing that we really didn't get into were packages.
    We did some GUI design, but not a whole lot.
    The programming that I do with Matlab is very similar to C. (i.e. highly procedural not Object Oriented) so I think that's where some of my stumbling blocks are. I feel pretty comfortable reading Java code and using the API (sort of) but I didn't even know that 2D intersections existed.
    I have just started using eclipse last week. My previous coding was just done with textpad, so I am trying to get used to compiling code and building projects (and .jars) with an IDE.
    Thank you for the tips. I am going to keep looking around and see what I can find.

  • Programmatically select multiple rows in DataGrid

    Hello,
    I'm trying to do it for days. How can i select many rows in my DataGrid in the code. In my DataGrid i have rows responsible for folders and files - existing in these folders. When user selects folder row i want to select all rows responsible for files that
    are in that folder. Of course i know which rows should be selected, but the problem is how to do it? I can add that my DataGrid is Binded to ObservableCollection(containing strings with pathes to different directories and files. Please some help.

    Hi Josef,
    I am marking this issue as "Answered". If you have any new questions or concerns about this issue, please feel free to let me know.
    Thank you and have a nice day!
    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Contiguous and non-contiguous multiple cell selection in JTable

    I desparately need your help on this.
    My appliaction contains a JTable. The users should be permitted to select multiple cells (both contiguous and non-contiguous) using
    Ctrl + Click -- add that cell the already existing selection
    Shift + Click -- add all cells in the range to the selection.
    I like to have the selection behaviour as that in Excel (where you could ctrl + click on any cell to add it to selection).
    Questions:
    ==========
    Is this behavior possible using JTable?
    How to do this?

    Hi, use
    JTable table = new JTable();
    DefaultListSelectionModel  dlm =  new DefaultListSelectionModel();
    dlm.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION  ); //1( the first one should be the one you are looking for)
    or (choose 1 or 2, the rest stays the same)
    dlm.setSelectionMode( ListSelectionModel.SINGLE_INTERVAL_SELECTION );//2
    table.getColumnModel().setSelectionModel(dlm);
    table.setCellSelectionEnabled(true);Hope this helps.
    Greetings Michael.

  • Multiple Cell Selection in a JTable (again...)

    Hi All -
    I'm trying to get a JTable working well with the ability to select multiple cells in the way you'd expect to be able to (in Excel for example). By this I mean, hold down ctrl to add to a selection, hold shift to select between the last selection and the new one, be able to drag multiple regions with the mouse and have them be selected.
    I've seen lots of talk about this, for example on this thread:
    http://forum.java.sun.com/thread.jspa?threadID=619580&start=0&tstart=0
    (the code here will not work in the 'general' case, for example it doesn't really support dynamic table resizing)
    ...and found some pretty extensive code from here:
    http://www.codeguru.com/java/articles/663.shtml
    ...that kinda half works. (but the selection model is very strange once you get it running. Not at all what the average user would be used to)
    Does anyone have this working 100% with code they can share? It is very surprising to me that this is not the default behavior in Swing to be honest.
    I'm sure that I can come up with a solution for my situation, but I may as well not waste the time if someone already has something working for this.
    Thanks!

    If you have columnSelectionAllowed,rowselectionAllowed and cellSelectionEnabled then you can select cell by cell if you use the control key,
    Now the problem is, if you don't have input by your keyboard, in my case, I have a big table and I need to select diferent cells that match a certain criteria,
    jTable2.setRowSelectionInterval(j,j); //but this only works not for different rows 5 - 120 - 595
    I'm trying to use:
    jTable2.changeSelection()
    but still don't have good results....
    If any one could help to this matter will be really appreciated...
    thanks...

  • Multiple Cell Selection inJTable

    I want to select multiple cells ( 4 consequent cells) with single mouse click.The problem is the 4 cells are getting selected ,but the border is being set to only one cell on which i clicked,but the selection background color is set to all the four.
    i want the border to be included for all the four cells ,so that it looks like i have selected a set of cells .
    waiting for a reply.
    please help.

    In order to accomplish this, you will have to drastically modify the UI delegate for JTable. The difference between the areas you are speaking of is that one is the 'selection' and the one with the border is the 'focus' cell which represents the 'anchor' of the selection.
    The actual routines that paint the table cells are marked as private in the BasicTableUI class, so that is not a workable solution.
    Let this be a lesson to all Java programmers (ahem) about making critical methods private!
    Mitch

Maybe you are looking for

  • Adding text to a eps?

    Hi. I downloaded a eps file from shutterstock. It is easy all editable and I downloaded Adobe Illustrator trial version. I was able to add text at one point of the image. I want to be able to add another section of text and add the splatter effect to

  • Download SAP Report in Spreadsheet Format with automatic Save As selection

    Hi All, I'm using an Excel sheet that links up to SAP to grab some data off of QE03. Due to the nature of my data, I have to save the data into Excel/Spreadsheet format (aka this button ) BUT, when you click that button it stops the script for a "Sav

  • Why does it take for a month to get internet services?

    I'd like to know why does it take for a month to get internet services? I ordered my service on Jan 18,2012 and I got the installation kit on Jan 21,2012. But I can't  use the internet and I have to wait until Feb 9,2012 for my service ready date. I

  • HasViewList is showing in object browser as obsolete

    My machine has BOE XI 3.1 .NET SDK and Crystal Reports 2008 installed. I am developing in Visual Studio 2003.  My object browser displays CrystalDecisions.Web.CrystalReportviewer.HasVewList as a valid property. However, my coworker is showing that sa

  • Having problems organizing my library

    For some reason, when I organize my library by albums, some of my songs are appearing underneath my videos, and I can't figure out how to move them above the videos.