- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 JavaFX 中禁用多个相同“类型”的按钮。例如,我有多个用于不同操作的取消按钮,但我想同时启用/禁用它们,但似乎我无法在 LinkedList 中访问它们。
在下面的“最小且可重现”示例中,当按下开始时,它应该启用(在 fxml 中默认禁用)取消按钮,但它没有。
DemoController.java
public class DemoController {
@FXML
Button startBtn;
@FXML
Button cancelBtn1; // disabled by default
@FXML
Button cancelBtn2; // disabled by default
@FXML
Tab tab1;
public SDK sdk;
List<Node> cancelBtnGroup = new LinkedList<Node>();
public void initialize() {
cancelBtnGroup.add(cancelBtn1);
cancelBtnGroup.add(cancelBtn2);
startBtn.setOnAction(event -> {
tab1.setDisable(true);
startBtn.setDisable(true);
System.out.println("Disabling cancel buttons");
HashMap<String, String> test = new HashMap<String, String>();
test.put("disableCancel", "false");
sdk.onEvent(test);
});
initializeSDK();
}
public void initializeSDK() {
sdk = new SDK() {
@Override
public void onEvent(HashMap<String, String> e) {
if(e.containsKey("disableCancel")) {
for(Node btn : cancelBtnGroup) {
btn.setDisable(Boolean.parseBoolean(e.get("disableCancel")));
}
}
}
};
}
}
似乎我正在以某种方式覆盖按钮,但我不知道如何操作。我觉得我不了解某些功能的范围。我试图使代码尽可能简化和可读,所以如果我遗漏了一些非常明显的东西,这可能就是原因。 SDK 对象不包含具有相同名称的对象,为了确保这不是我更改名称的问题。
最佳答案
根据您发布的代码,我无法确定它不起作用的原因。但是,这是一个使用禁用共同祖先方法和 FXML 的最小示例:
App.java
package com.example;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
var root = FXMLLoader.<Parent>load(getClass().getResource("/App.fxml"));
var scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
}
App.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<VBox xmlns="http://javafx.com/javafx/13" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.example.Controller" spacing="10" prefWidth="500" prefHeight="300"
alignment="CENTER">
<padding>
<Insets topRightBottomLeft="10"/>
</padding>
<ToggleButton fx:id="toggleBtn"/>
<HBox fx:id="container" alignment="CENTER" spacing="10">
<Button text="Button #1"/>
<Button text="Button #2"/>
<Button text="Button #3"/>
<Button text="Button #4"/>
</HBox>
</VBox>
Controller.java
package com.example;
import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.HBox;
public class Controller {
@FXML private ToggleButton toggleBtn;
@FXML private HBox container;
@FXML
private void initialize() {
toggleBtn.textProperty().bind(
Bindings.when(toggleBtn.selectedProperty())
.then("Disable Buttons")
.otherwise("Enable Buttons")
);
container.disableProperty().bind(toggleBtn.selectedProperty().not());
}
}
注意:除了在代码中绑定(bind)容器的 disable
属性之外,还可以使用以下方法完成上述操作:
<!-- Everything else omitted for brevity -->
<HBox disable="${!toggleBtn.selected}">
当然,如果您使用 ToggleButton
以外的东西,那么在 FXML 中实现绑定(bind)可能不可行。
关于java - 在 JavaFX 中同时启用/禁用组按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58511260/
我想知道如何首先检测 Javascript 是否启用/禁用。在此站点上禁用 javascript 表明 stackoverflow 使用了称为标签的东西。 这是标准的做法吗?它适用于所有浏览器吗?它不
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: How to enable PHP short tags ? Enable short open tags
在 VSTS (Azure DevOps) 上拥有私有(private)存储库我尝试通过将以下内容添加到 .csproj 文件来启用 SourceLink:https://github.com/dot
我创建了一个 wx.Frame(我们称之为 mainFrame)。该框架上包含一个按钮,当单击该按钮时,会创建一个新框架(我们称之为 childFrame)。 我想知道如何在创建 childFrame
当我禁用 WPF 中的控件时,比如说一个菜单项 MenuItem aMenuItem = ... aMenuItem.IsEnabled = false; MenuItem 中的文本仍然处于事件状态,
我想在我的 nginx 服务器上启用 gzip 压缩。 nginx.conf 文件在这里: http { # Enable Gzip server { location ~* \.(?
我正在使用免费的 heroku 附加 PG 备份并遵循这些 instructions .我找到了安装应用程序的命令:heroku addons:add pgbackups:auto-week。但是我想
我想知道脚本是否可以使用某种切换按钮启用/禁用页面上的所有输入元素。 我用谷歌搜索了它,但除了这个之外没有发现任何有用的东西: http://www.codetoad.com/javascript/e
在我的 php 文件中,我想使用 jQuery Datepicker。 当我的文件加载时,我创建了禁用的日期选择器。 然后,当我的 php 文件(它是一个表单)中的一个特殊字段被填充时,我想启用日期选
我有一个按钮,如下所示: RadButton lnkAdd = new RadButton(); lnkAdd.ID = "BtnAdd"; lnkAdd.CommandName = RadGrid.
public static void ToggleTaskManager(string keyValue) { RegistryKey objRegistryK
我正在 Azure 中使用事件网格订阅,该订阅在创建 Blob 时触发。然而,我们有很多文件进入这个 blob,比如说 1000 多个。 如果我发现任何文件有任何错误,我想做的是禁用事件订阅。 最佳答
我的网站上有几个使用 HTML5 contentEditable 属性的 div。目标是让用户能够开始编写日记条目,并将保存按钮从禁用更改为启用。 这是我目前拥有的 HTML: Write
我有一个范围输入,其定义如下: @Html.LabelFor(m => Model.Quality, Resources.CompressionQuality) 和一个下拉菜单: @Html.Lab
我正在尝试创建一个启用/禁用按钮的下拉菜单,并且我正在关注此 example 但它已经有 4 年历史了,而且该功能似乎无法在我的 xhtml 页面上运行。 任何帮助都将被适当 最佳答案 这是一个现场演
我正在 Azure 中使用事件网格订阅,该订阅在创建 Blob 时触发。然而,我们有很多文件进入这个 blob,比如说 1000 多个。 如果我发现任何文件有任何错误,我想做的是禁用事件订阅。 最佳答
我在这里遇到一个非常奇怪的情况:我编写了一个应用程序,除其他外,将连接的代理从打开切换到关闭,反之亦然。通过更改注册表中的值来完成此操作: public void SetUpProxy(string
我需要调整一堆 PVC 的大小。似乎最简单的方法是通过ExpandPersistentVolumes 功能。但是我无法获得配置合作。 ExpandPersistentVolumes feature g
如果我的TextField为空,则应禁用该按钮,并且该按钮的textColor和borderColor应该为灰色。但是,启用按钮后,颜色应为蓝色。 更改textColor很容易: button.Set
您好,我的问题是:我无法从另一个类启用表单的按钮。我的表单类是 public class FileSending { //Function for enabling the button
我是一名优秀的程序员,十分优秀!