Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 对TableView排序时出现CheckBoxTableCell错误_Java_Javafx 8 - Fatal编程技术网

Java 对TableView排序时出现CheckBoxTableCell错误

Java 对TableView排序时出现CheckBoxTableCell错误,java,javafx-8,Java,Javafx 8,当通过单击列标题对TableView进行排序时,复选框行为会变得异常。如果选中其中一个,则另一个似乎已绑定到它,并且也将被选中 在对TableView进行排序之前,所有操作都按预期进行,但一旦触发排序,该行为将是意外的 我使用的是CheckBoxTableCell,在64位Windows 8上运行JDK1.8.0-ea-b10664位 以下是SSCCE: import javafx.application.Application; import javafx.beans.property.Boo

当通过单击列标题对TableView进行排序时,复选框行为会变得异常。如果选中其中一个,则另一个似乎已绑定到它,并且也将被选中

在对TableView进行排序之前,所有操作都按预期进行,但一旦触发排序,该行为将是意外的

我使用的是
CheckBoxTableCell
,在64位Windows 8上运行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);
        }
    }
}
导入javafx.application.application;
导入javafx.beans.property.BooleanProperty;
导入javafx.beans.property.SimpleBoleAnProperty;
导入javafx.beans.property.SimpleStringProperty;
导入javafx.beans.property.StringProperty;
导入javafx.collections.FXCollections;
导入javafx.collections.ObservableList;
导入javafx.collections.transformation.SortedList;
导入javafx.scene.scene;
导入javafx.scene.control.TableColumn;
导入javafx.scene.control.TableView;
导入javafx.scene.control.cell.CheckBoxTableCell;
导入javafx.scene.control.cell.TextFieldTableCell;
导入javafx.scene.layout.StackPane;
导入javafx.stage.stage;
/**
*作者:Anas H.Sulaiman(ahs.pw)
*/
公共类CheckBoxTableCellBug扩展应用程序{
公共静态void main(字符串[]args){
发射(args);
}
@凌驾
public void start(Stage)引发异常{
ObservableList persons=FXCollections.observableArrayList();
添加(新的人(“萨米”,“哈达德”,假));
添加(新的人(“艾哈迈德”、“哈桑”,真));
人员。添加(新人员(“Rami”、“Kassar”,真));
添加(新的人(“内哈德”,“哈马德”,假));
人员。添加(新人员(“Jamal”、“Raei”,真));
人员。添加(新人员(“Ameer”、“Raji”,真));
人员。添加(新人员(“Tahseen”、“Muhsen”,真));
SortedList SortedList=新的SortedList(人);
TableView表格=新表格视图(分类列表);
sortedList.comparatorProperty().bind(table.comparatorProperty());
table.setEditable(true);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_策略);
TableColumn colFirstName=新的TableColumn(“名字”);
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 colLastName=新的TableColumn(“姓氏”);
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 colInvited=新的TableColumn(“邀请”);
colInvited.setCellValueFactory(p->p.getValue().invested);
colInvited.setCellFactory(CheckBoxTableCell.forTableColumn(colInvited));
table.getColumns().addAll(colFirstName、colLastName、colInvited);
stage.setScene(新场景(新StackPane(table));
stage.setTitle(“CheckBoxTableCell Bug”);
stage.show();
}
班主任{
公共财产名;
公共财产姓氏;
欢迎市民购买公共物业;
公众人士(){
this.firstName=新的SimpleStringProperty(“”);
this.lastName=新的SimpleStringProperty(“”);
this.invested=新的SimpleBoleAnProperty(false);
}
公众人物(字符串fname、字符串lname、布尔值){
这个();
this.firstName.set(fname);
this.lastName.set(lname);
本.邀请.集(邀请);
}
}
}
如何重现错误:

  • 单击“First Name”列的标题对表进行排序
  • 尝试选择“邀请”列中的第一个复选框
  • 尝试选择“邀请”列中的第三个复选框
  • 正如预期的那样,该bug也出现在集成(JavaFX示例附带的应用程序)中


    有没有解决这个问题的办法?

    已经解决了。我不确定该修复程序是在哪个版本中首次发布的,但我使用的是build 114,在该版本中修复了该漏洞。

    将该漏洞归档到jira上……归档一个漏洞结果是一个简单的过程。。以前从未试过,因为这是我第一次染上虫子。。在我归档之后,我记得在不同的操作系统和不同的用例上搜索它。如果需要,他们会将其标记为重复。从2014年4月3日起,这个错误在1.8.0-b132(64位)中仍然很明显