Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX - Cannot call setOnAction() on ChoiceBox?

Simple question:

I've DEFINITELY used setOnAction for ChoiceBox<T> before, but it claims there is no such method of the ChoiceBox class. I'm using a different computer and have installed the Ex(fx)clipse plugin. At the bottom of this thread are my imports. I also have proof that I have used this method of ChoiceBox before. What is wrong? It must be something outrageously simple. I don't understand how I was able to write it before and yet I don't see it in the JavaFX API page.

Edit:

Runnable version of my class here.

Instance Variables

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;

Code block in my method body:

// 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

My Imports

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;
like image 450
Hatefiend Avatar asked Dec 07 '25 06:12

Hatefiend


1 Answers

EDIT:

It turned out that the setOnAction method was only added to the ChoiceBox API starting from the 8u60 version of the JDK.

enter image description here

like image 120
Mohammed Aouf Zouag Avatar answered Dec 09 '25 20:12

Mohammed Aouf Zouag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!