2013-09-23 27 views
2

当通过单击列标题对TableView进行排序时,复选框的行为变得意外。如果你检查其中一个,另一个似乎被绑定,并且被选中。TableView排序时出现CheckBoxTableCell错误

在对TableView进行排序之前,一切都按预期工作,但是一旦排序被触发,行为就会出现意外。

我使用CheckBoxTableCell,在Windows 8 64bit上运行JDK 1.8.0-ea-b106 64位。

这里是一个SSCCE:

import javafx.application.Application; 
import javafx.beans.property.BooleanProperty; 
import javafx.beans.property.SimpleBooleanProperty; 
import javafx.beans.property.SimpleStringProperty; 
import javafx.beans.property.StringProperty; 
import javafx.collections.FXCollections; 
import javafx.collections.ObservableList; 
import javafx.collections.transformation.SortedList; 
import javafx.scene.Scene; 
import javafx.scene.control.TableColumn; 
import javafx.scene.control.TableView; 
import javafx.scene.control.cell.CheckBoxTableCell; 
import javafx.scene.control.cell.TextFieldTableCell; 
import javafx.scene.layout.StackPane; 
import javafx.stage.Stage; 

/** 
* Author: Anas H. Sulaiman (ahs.pw) 
*/ 
public class CheckBoxTableCellBug extends Application { 
    public static void main(String[] args) { 
     launch(args); 
    } 

    @Override 
    public void start(Stage stage) throws Exception { 
     ObservableList<Person> persons = FXCollections.observableArrayList(); 
     persons.add(new Person("Sami", "Haddad", false)); 
     persons.add(new Person("Ahmed", "Hasan", true)); 
     persons.add(new Person("Rami", "Kassar", true)); 
     persons.add(new Person("Nehad", "Hamad", false)); 
     persons.add(new Person("Jamal", "Raei", true)); 
     persons.add(new Person("Ameer", "Raji", true)); 
     persons.add(new Person("Tahseen", "Muhsen", true)); 

     SortedList<Person> sortedList = new SortedList<>(persons); 
     TableView<Person> table = new TableView<>(sortedList); 
     sortedList.comparatorProperty().bind(table.comparatorProperty()); 
     table.setEditable(true); 
     table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); 

     TableColumn<Person, String> colFirstName = new TableColumn<>("First Name"); 
     colFirstName.setCellValueFactory(p -> p.getValue().firstName); 
     colFirstName.setCellFactory(TextFieldTableCell.forTableColumn()); 
     colFirstName.setOnEditCommit(event -> event.getTableView().getItems().get(event.getTablePosition().getRow()).firstName.set(event.getNewValue())); 

     TableColumn<Person, String> colLastName = new TableColumn<>("Last Name"); 
     colLastName.setCellValueFactory(p -> p.getValue().lastName); 
     colLastName.setCellFactory(TextFieldTableCell.forTableColumn()); 
     colLastName.setOnEditCommit(event -> event.getTableView().getItems().get(event.getTablePosition().getRow()).lastName.set(event.getNewValue())); 

     TableColumn<Person, Boolean> colInvited = new TableColumn<>("Invited"); 
     colInvited.setCellValueFactory(p -> p.getValue().invited); 
     colInvited.setCellFactory(CheckBoxTableCell.forTableColumn(colInvited)); 

     table.getColumns().addAll(colFirstName, colLastName, colInvited); 

     stage.setScene(new Scene(new StackPane(table))); 
     stage.setTitle("CheckBoxTableCell Bug"); 
     stage.show(); 
    } 

    class Person { 
     public StringProperty firstName; 
     public StringProperty lastName; 
     public BooleanProperty invited; 

     public Person() { 
      this.firstName = new SimpleStringProperty(""); 
      this.lastName = new SimpleStringProperty(""); 
      this.invited = new SimpleBooleanProperty(false); 
     } 

     public Person(String fname, String lname, boolean invited) { 
      this(); 
      this.firstName.set(fname); 
      this.lastName.set(lname); 
      this.invited.set(invited); 
     } 
    } 
} 

如何重现bug:

  1. 点击一次“名”列的标题进行排序表
  2. 请尝试选择“邀请”列中的第一个复选框
  3. 尝试选中“已邀请”列中的第三个复选框

正如预期的那样,该错误也出现在Ensemble(JavaFX Samples附带的应用程序)中。

任何想法如何解决这个问题?

+0

将文件上的bug报告给jira ... – assylias

+0

将一个错误归档为一个简单的过程..从未尝试过,因为这是我第一次发现一个bug .. [https: //javafx-jira.kenai.com/browse/RT-33108) 我提交之后,我记得要搜索它,并且[在它之前找到它](https://javafx-jira.kenai.com/browse/RT-32208)在不同的操作系统和不同的用例上。 –

+0

如有必要,他们会将其标记为重复。 – assylias

回答

1

The bug已被修复。我不确定修复程序在哪个版本中首次发布,但是我使用的是版本114,其中修复了该错误。

+0

这个bug在1.8.0-b132(64bit)中仍然很明显,截至2014年4月3日 – 2014-04-03 18:20:31