JavaFX之TableView的TableRow

TableRow

通过TableView的setRowFactory,对行的双击进行操作 

 

 

[java] view plain copy
 
  1. tableView.setRowFactory(new Callback<TableView<T>, TableRow<T>>() {    
  2.            @Override    
  3.            public TableRow<T> call(TableView<T> param) {    
  4.                return new TableRowControl();    
  5.            }    
  6.        });    
[java] view plain copy
 
  1. class TableRowControl extends TableRow<T> {    
  2.     
  3.         public TableRowControl() {    
  4.             super();    
  5.             this.setOnMouseClicked(new EventHandler<MouseEvent>() {    
  6.                 @Override    
  7.                 public void handle(MouseEvent event) {    
  8.                     if (event.getButton().equals(MouseButton.PRIMARY)    
  9.                             && event.getClickCount() == 2    
  10.                             && TableRowControl.this.getIndex() < tableView.getItems().size()) {    
  11.                           //doSomething    
  12.                     }    
  13.                 }    
  14.             });    
  15.         }    
  16.     }    

 

posted @ 2016-10-14 20:51  茅坤宝骏氹  阅读(1551)  评论(0编辑  收藏  举报