Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8094817

Processing DND detection on a TableView causes the dragging of columns to fail

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u20
    • Fix Version/s: 8u20
    • Component/s: javafx
    • Labels:
    • Environment:

      Java 8u-dev repo tip, Linux

      Description

      In our application we allow the dragging of a table row to another portion of our ui. For simplicity this is implemented using an onDragDetected handler set on the TableView since all it has to do is put the currently selected rows into the clipboard.

      This strategy works will with the initial release of Java 8 but in 8u20 it causes the drag reordering of Table columns to fail.

      To reproduce run the following test class:

      1. Drag and drop a selected row to another text widget to see the DND support work.

      2. Next try dragging on a column header to change their order. It will start to drag and then fail.

      3. If you comment out the onDragDetected handler and run again the Table columns can be reordered as expected.

      ******************************************** Test Class *************************************************
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.TableCell;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.input.ClipboardContent;
      import javafx.scene.input.Dragboard;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.input.TransferMode;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      public class HeaderTest extends Application {

          @Override public void start(Stage primaryStage) {
             
              TableView<String> table = new TableView<>();
              // add some rows
              for ( int i = 1; i <= 25; i++ ) {
                  table.getItems().add("" +i);
              }
              
              // add some columns
              for ( int i = 0; i < 5; i++ ) {
                  final TableColumn<String, String> column =
                        new TableColumn<>("Column " + i);
                  column.setPrefWidth(100);
                  final int columnIndex = i;
                  column.setCellFactory(c -> new TableCell<String, String>() {
                     @Override protected void updateItem(String item, boolean empty) {
                         super.updateItem(item, empty);
                         if ( empty || getTableRow() == null ) {
                             setText("");
                         } else {
                             setText("row " + getTableRow().getItem() + ", " +
                                   "column " + columnIndex);
                         }
                     }
                 }) ;
                  
                  table.getColumns().add( column );
              }
              
              // setup simple DND of row data...
              table.setOnDragDetected(( MouseEvent event) -> {
                 String sel = table.getSelectionModel().getSelectedItem();
                 if ( sel != null ) {
                    Dragboard db = table.startDragAndDrop(TransferMode.COPY);
                    ClipboardContent content = new ClipboardContent();
                    content.putString(sel);
                    db.setContent(content);
                    event.consume();
                 }
              });
              
              primaryStage.setScene(new Scene(new StackPane(table), 550, 250));
              primaryStage.show();
          }

         public static void main(String[] args) {
              launch(args);
          }

      }

        Attachments

          Activity

            People

            Assignee:
            jgiles Jonathan Giles
            Reporter:
            csmithjfx Charles Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: