有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JavaFX无法在ChoiceBox上调用setOnAction()?

简单问题:

我以前肯定用过setOnAction来表示ChoiceBox<T>,但它声称ChoiceBox类没有这样的方法。我正在使用另一台计算机,并安装了Ex(fx)clipse插件。在这个线程的底部是我的导入。我也有证据证明I have used this method of ChoiceBox before。怎么了?这一定是非常简单的事情。我不明白我以前是怎么写的,但是我在JavaFX API page中没有看到它

编辑:

Runnable version of my class here

实例变量

private VBox root;
private Scene scene;
private static Stage stage;
private Label consoleTitle;
private static TextArea console;
private Button startBtn, endBtn, calibrateBtn, calibrateAreaBtn;
private ChoiceBox<String> lureCB;
private CheckBox lureCKB;
private HBox buttonHB, lureHB;

我的方法体中的代码块:

// ChoiceBox for the type of lures.
lureCB = new ChoiceBox<>();
lureCB.getItems().addAll("Test",
        "Test",
        "Test",
        "Test",
        "Test",
        "Test");
lureCB.setVisible(false);
lureCB.setOnAction(e ->
{

});

Image

我的进口产品

package gui;

import java.awt.AWTException;
import java.awt.Robot;
import java.time.LocalTime;

import program.*;
import javafx.application.Application;
import javafx.scene.control.Button;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.geometry.Insets;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.Tooltip;
import javafx.scene.text.Font;
import javafx.geometry.Pos;
import javafx.scene.paint.Color;

共 (1) 个答案

  1. # 1 楼答案

    编辑:

    原来setOnAction方法只是从JDK的8u60版本开始添加到ChoiceBoxAPI中

    enter image description here