小编Wer*_*erb的帖子

使用自定义单元格工厂的ListView在删除项目后不会更新

我正在学习JavaFX,我想创建一个正常工作的单元工厂,直到我想删除我的一行ListView:

plateList.setCellFactory(new Callback<ListView<Car>, ListCell<Car>>() {

        @Override
        public ListCell<Car> call(ListView<Car> param) {
            ListCell<Car> cell = new ListCell<Car>() {

                @Override
                protected void updateItem(Car item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null) {
                       setText(item.getPlate());
                    }
                }
            };
            return cell;
        }
    });
Run Code Online (Sandbox Code Playgroud)

我正在填充ListView一些示例数据:

ObservableList<Car> sample = FXCollections.observableArrayList();
    sample.add(new Car("123-abc", "opel", "corsa", 5.5));
    sample.add(new Car("123-cba", "vw", "passat", 7.5));
    plateList.setItems(sample);
Run Code Online (Sandbox Code Playgroud)

现在我将看到我期望的ListView将是以下内容:

  • 123-ABC
  • 123-CBA

如果删除行ex:第一行(123-abc),ListView将如下所示:

  • 123-CBA
  • 123-CBA

这是删除部分:

@FXML
private void deleteBtnAction() {
   plateList.getItems().remove(plateList.getSelectionModel().getSelectedItem());
    ObservableList<Car> t = …
Run Code Online (Sandbox Code Playgroud)

java listview javafx

7
推荐指数
2
解决办法
1万
查看次数

如何将mpg嵌入我的网页

我想将mpg(兼容DVD的mpeg2)电影文件嵌入到我的网页中.我没有机会将这些视频转换为任何其他格式.此网站仅供个人使用,因此任何类型的解决方案都是完美的.

真的适合任何建议或解决方案.

这是我的代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<embed src="my_video.mpg" autostart="false" height="350" width="500" />

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

解决了:

我对这个问题的解决方案是我必须为我的浏览器重新安装wmp插件并且工作正常

html javascript php mpeg

5
推荐指数
1
解决办法
2万
查看次数

条件绑定

我是JavaFx的新手,我正在创建一个用户必须填写一些表单的应用程序,我想用绑定"预先验证"它们.像这些元素一样的简单东西可以是空的,或者其中一些只能包含数字.这是我到目前为止:

saveBtn.disableProperty().bind(Bindings.when(
            departureHourText.textProperty().isNotEqualTo("")
                    .and(isNumber(departureHourText.getText())))
            .then(false)
            .otherwise(true));
Run Code Online (Sandbox Code Playgroud)

这是我的isNumber方法:

private BooleanProperty isNumber(String string) {
    return new SimpleBooleanProperty(string.matches("[0-9]+"));
}
Run Code Online (Sandbox Code Playgroud)

但无论我在TextField中输入什么内容,按钮都会被禁用.

任何帮助是极大的赞赏.

UPDATE

当我评估这个表达式时:departureHourText.textProperty().isNotEqualTo("") 结果将是:BooleanBinding [invalid]

java javafx javafx-8

5
推荐指数
1
解决办法
4952
查看次数

Thymeleaf +弹簧动态更换

是否有可能在Thymeleaf中创建动态替换?

我有以下控制器:

@Controller
public class LoginController {

    @RequestMapping("/login")
    public String getLogin(Model model){
        model.addAttribute("template","login");
        return "index";
    }
}
Run Code Online (Sandbox Code Playgroud)

以下观点:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" >
<head></head>
<body>

<div th:replace="fragments/${template} :: ${template}"></div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Error resolving template "fragments/${template}", template might not exist or might not be accessible by any of the configured Template Resolvers
Run Code Online (Sandbox Code Playgroud)

UPDATE

我试图像这样预处理我的变量:

<div th:replace="fragments/${__#{${template}}__} :: ${__#{${template}}__}"></div>
Run Code Online (Sandbox Code Playgroud)

现在${template}如何取代login我现在有以下错误:

Exception evaluating SpringEL expression: "??login_en_US??"
Run Code Online (Sandbox Code Playgroud)

spring thymeleaf

4
推荐指数
2
解决办法
1万
查看次数

抛出异常不会抛出

我刚开始学习java.我正在尝试学习异常处理的工作原理,所以我编写了一个小程序:

public class Car {
    protected String type;
    protected String[] colors;
    protected boolean isAvaiable;

    public Car(String type, Collection<String> colors, boolean isAvaiable) throws NoColorException {
        if (colors == null || colors.isEmpty()) {
            throw new NoColorException("No colours!");
        } else {
            this.type = type;
            this.colors = (String[]) colors.toArray();
            this.isAvaiable = isAvaiable;
        }
    }

    public static void main(String[] args) {
        try {
            Car n = new Car("asd", new ArrayList(), true);
        } catch (NoColorException ex) {

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的Exception类:

public class NoColorException extends Exception …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
62
查看次数

标签 统计

java ×3

javafx ×2

html ×1

javafx-8 ×1

javascript ×1

listview ×1

mpeg ×1

php ×1

spring ×1

thymeleaf ×1