- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
左列:用于选择或取消选择行的复选框,默认选中。右列:一个字符串,表示直到并包括该行的所选行的数量。因此,取消选中一行中的复选框会更改下方行中的值。
错误:向下滚动到表格底部。取消选中邀请代码为 74 的行中的复选框。再次选中它。最后三个邀请码应再次显示为 73、74 和 75。但通常情况下,它们会显示 73、73、74 或 73、74、74。
错误并不总是发生!如果没有出现,用表格的滚动条上下滚动一点,重复上面的过程就可以出现。
似乎这个错误只是视觉上的——我让它把 ObservableList 的内容转储到控制台,它显示了正确的值。除了这个视觉故障,我的应用程序运行正常。单击窗口中的任何其他控件(例如表格的滚动条)会将表格中的邀请代码翻转为正确的值。切换到我桌面上的另一个工作区并返回,它也会显示正确的值。
Small image ,在左侧显示 ObservableList 的控制台转储,在右侧显示有问题的表。
问题 非常合乎逻辑:我怎样才能消除这个错误!?
编辑:按照 Kleopatra 的建议丢弃了更多代码。谢谢!
MCV:
FXMLDocumentController.java
package invcodebug;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.CheckBoxTableCell;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.util.Callback;
public class FXMLDocumentController implements Initializable {
@FXML private TableView<Person> personTable;
@FXML private TableColumn<Person, Boolean> invitedCol;
@FXML private TableColumn<Person, String> inviteCodeCol;
private final ObservableList<Person> persons
= FXCollections.observableArrayList();
@Override
public void initialize(URL location, ResourceBundle resources) {
initPersonTable();
populatePersons();
}
private void initPersonTable() {
invitedCol.setCellValueFactory(new PropertyValueFactory<>("invited"));
inviteCodeCol.setCellValueFactory(new PropertyValueFactory<>("inviteCode"));
invitedCol.setCellFactory(CheckBoxTableCell.forTableColumn(new Callback<Integer, ObservableValue<Boolean>>() {
@Override
public ObservableValue<Boolean> call(Integer param) {
doInvCode();
// SHOWS: underlying ObservableList has correct values
System.out.println("--------------------------");
for (Person p : persons) {
System.out.println(p.isInvited() + " " + p.getInviteCode()
);
}
return persons.get(param).invitedProperty();
}
}));
personTable.setItems(persons);
}
private void doInvCode() {
int invCounter = 1;
for (Person p : persons) {
if (p.isInvited()) {
p.setInviteCode(((Integer) invCounter).toString());
invCounter++;
} else p.setInviteCode("");
}
}
private void populatePersons() {
for (int i = 0; i < 75; i++) {
persons.add(new Person(true, ""));
}
}
}
Person.java
package invcodebug;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
public class Person {
private final SimpleBooleanProperty invited;
private final SimpleStringProperty inviteCode;
public Person(boolean invited, String inviteCode) {
this.invited = new SimpleBooleanProperty(invited);
this.inviteCode = new SimpleStringProperty(inviteCode);
}
public boolean isInvited() {
return invited.get();
}
public SimpleBooleanProperty invitedProperty() {
return invited;
}
public String getInviteCode(){
return inviteCode.get();
}
public void setInviteCode(String invCode) {
this.inviteCode.set(invCode);
}
public SimpleStringProperty inviteCodeProperty() {
return inviteCode;
}
}
FXML文档.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" prefHeight="464.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="invcodebug.FXMLDocumentController">
<children>
<TableView fx:id="personTable" editable="true" layoutX="26.0" layoutY="28.0" prefHeight="347.0" prefWidth="572.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="20.0">
<columns>
<TableColumn fx:id="invitedCol" prefWidth="27.0" sortable="false" />
<TableColumn fx:id="inviteCodeCol" editable="false" prefWidth="110.0" resizable="false" sortable="false" text="Invite Code" />
</columns>
</TableView>
</children>
</AnchorPane>
InvCodeBug.java
package invcodebug;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class InvCodeBug extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
最佳答案
可能不是最技术性的答案,但是通过在 doInvCode()
方法的末尾使用 personTable.requestFocus();
,表格在视觉上被刷新并且看起来解决问题。
关于java - 如何解决我的 JavaFX TableView 中的这个视觉故障?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36674184/
当我尝试以非整数的步长(例如,每帧 0.5 像素)在屏幕上移动图形对象时,这会导致移动不稳定和“滞后”;因为对象只会每两帧移动 1 个像素。 我理解为什么会发生这种情况,因为对象的 x/y 值必须是整
市面上有大量的家谱应用程序,但出于某种原因,我找不到一个示例来说明如何为 Android 应用程序创建一个。我是否使用 Canvas ,是否有图表库? 我的基本要求是画一个三层的树(节点)图/图表,其
[ {name: 'John'}, {name: 'Plasmody'}, {name: 'Kugelschreiber'}, {name: 'Sarrah'}, ] 如果我在 J并做
我试图定位所有没有 www 的链接。在数据库中。 https://launchhousing.org.au 并替换为 https://www.launchhousing.org.au 我使用了“搜索和
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
我需要排除具有以下模式的文件: ProjectFoo.Data[0-9]{14}.lgp 如何将 RegEx 用于 (Visual)SVN 忽略列表? 最佳答案 subversion 忽略列表不支持正
我正在寻找在处理中创建该项目的方法,但是,我发现该术语有点困难。我不确定如何调用在整个歌曲中线条永久保持的效果来“绘制”音乐数据。 对于我可以查看哪些教程或某人的回答,我将不胜感激。 我的目标是创建尽
我正在尝试为 android 制作游戏。我目前已将所有美术资源加载到 drawables 文件夹中,但我的问题是如何实际引用特定资源来渲染它? 我知道每个文件都有一个唯一的@id,我可能必须在onDr
Closed. This question is off-topic。它当前不接受答案。
只是一个简单的问题。 有一个简单的可视化工具可以生成iOS/QuartzCore的源代码吗? 例如,我会制作一个带有路径和a的CAKeyframeAnimation(例如CGPathMoveToPoi
编辑 3:我想这已经解决了。我刚刚启用了古腾堡编辑器并发现了它的“经典编辑器”部分,即代码编辑器。我唯一需要习惯的是我无法轻易修改的编辑器行高,这还不错。这对我有用,它超过了修改 functions.
我想在具有背景 slider 的可视 Composer 行内创建一个下拉菜单,最重要的是我要切换的链接。我在编辑自定义 css 时面临的问题是链接没有设置为 bottom:0;已设置position:
我正在学习 C++,并且了解一点 Visual Basic 和 Delphi。 但我想知道,有没有像 Delphi 这样的程序,但适用于 C++。您可以将按钮拖到窗体上,双击它,就像在 Delphi
我正在努力使用 pygame 初始化 OpenGL 显示。和pyopengl . import pygame pygame.init() pygame.display.set_mode((1920,
不确定我做错了什么。我创建了一个主题,除了我在可视化编辑器中创建帖子外,一切都很好。对我来说,这很好,但大多数用户不了解 HTML,因此无法真正进入并编辑代码。 在元素检查器(Chrome)中,文章是
我正在编写一个 C# 程序,它接受一堆参数并对数据点进行一些转换,然后将它们绘制到屏幕上。 在我的一个表单上,我有一堆文本框,我都想执行相同的 KeyPress 事件。在我只做一个 switch 语句
我正在创建 UML 事件图,我需要使用发送和接受信号,但我似乎找不到它。我试图用谷歌搜索它,但我似乎找不到任何东西。有谁知道我在哪里可以找到它们,或者它们在 Visio 中不存在? 最佳答案 想知道为
是 Haskell for Visual Studio 2005兼容VS2008 SP1 ? 最佳答案 您最初问题的答案是否定的。visual haskell 的代码是用 Haskell 编写的,并通
我正在使用 Visual Composer 开发我的 WordPress 网站。 我需要包含一个可分页的容器,但如果它可以像幻灯片一样就更好了。 This is my pageable contain
有哪些 Web 应用程序可以让我直观地(通过单击)使用任何 REST API 并生成一些代码(以任何语言)来捕捉我所描述的视觉内容? 与 Swagger 或 Google API Playground
我是一名优秀的程序员,十分优秀!