question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add actions on JFXButton

See original GitHub issue

Excuse me, I encountered a problem, the Action has been added to fxml, but it does not take effect in the Controller. My English is not very good, I found many articles, but I couldn’t find it. If anyone knows, please tell me. Thank you

fxml 

        <!-- 水平布局盒子-->
        <HBox spacing="20" style="-fx-padding: 0 0 0 50;">
            <JFXButton prefWidth="100" prefHeight="40" buttonType="RAISED" text="BUTTON"
                       style="-fx-font-size:14px;-fx-background-color:WHITE;" onAction="#click"/>
            <JFXButton prefWidth="100" prefHeight="40" buttonType="RAISED" text="COLORED"
                       style="-fx-text-fill:WHITE;-fx-background-color:#5264AE;-fx-font-size:14px;"/>
            <JFXButton prefWidth="100" prefHeight="40" buttonType="RAISED" text="DISABLED"
                       style="-fx-background-color:WHITE;-fx-font-size:14px;" disable="true"/>
        </HBox>

Controller

@ViewController(value = "/fxml/Button.fxml")
public final class ButtonController {


    public void click(ActionEvent mouseEvent) {
        System.out.println();
    }
}

it dose not work .can you tell me reason?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
AlQa-hOliccommented, May 28, 2020

Ok so here is what I understand. Take a look at the datafx tutorial 1.

@FXML
@ActionTrigger("myAction")
private Button actionButton;

@ActionMethod("myAction")
public void onAction() {
    clickCount++;
    resultLabel.setText("Button was clicked " + clickCount + " times");
}

I think what you are missing is the @ActionMethod('button-fx-id') annotation.

If just adding that does not work you may have to add the @ActionTrigger('button-fx-id') annotation too.

0reactions
AlQa-hOliccommented, May 28, 2020

Here is my wechat id: https://pastebin.com/kwzgBDkA

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding EventHandler to JavaFX Button - Baeldung
We learned how to add event handlers to JavaFX buttons and execute different actions depending on the type of event.
Read more >
com.jfoenix.controls.JFXButton.setOnAction java code examples
getChildren().add(glyphDetailViewer); ScrollPane scrollableGlyphs ... setOnAction((action) -> { FileChooser fileChooser = new FileChooser(); FileChooser.
Read more >
How to add an image to a button (action) in JavaFX?
You can create a Button by instantiating the javafx.scene.control.Button class. ... Create an ImageView object using the image object.
Read more >
com.jfoenix.controls.JFXButton#setOnAction
CENTER); //Create the 'ok'/close button JFXButton button = new JFXButton("ok"); //set button action listner for closing the alert button.
Read more >
Create new Button and Set Action Listener in JavaFX
1. Create a JavaFX Button. Import javafx.scene. · 2. Button Text. Set text for the JavaFX Button using Button. · 3. Set Action...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found