Skip to content

Instantly share code, notes, and snippets.

@Da9el00
Created May 28, 2021 15:08
Show Gist options
  • Select an option

  • Save Da9el00/10cc1f127347dae79f04a9e54eeb013d to your computer and use it in GitHub Desktop.

Select an option

Save Da9el00/10cc1f127347dae79f04a9e54eeb013d to your computer and use it in GitHub Desktop.
JavaFX JfoeniX dialog
package sample;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDialog;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.StackPane;
import java.net.URL;
import java.util.ResourceBundle;
public class Controller implements Initializable {
@FXML
private StackPane root;
@FXML
private JFXDialog dialog;
@FXML
private JFXButton acceptButton;
@FXML
private JFXButton declineButton;
@FXML
void showDialog(ActionEvent event) {
dialog.show();
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
//dialog.setTransitionType(JFXDialog.DialogTransition.NONE);
dialog.setDialogContainer(root);
declineButton.setOnAction(actionEvent -> {
System.out.println("Declined!");
dialog.close();
});
acceptButton.setOnAction(actionEvent -> {
System.out.println("Accepted");
dialog.close();
});
}
}
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXDialog?>
<?import com.jfoenix.controls.JFXDialogLayout?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?>
<StackPane fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<AnchorPane style="-fx-background-color: #ffffff;">
<children>
<JFXButton layoutX="231.0" layoutY="287.0" onAction="#showDialog" prefHeight="39.0" prefWidth="138.0" ripplerFill="BLACK" style="-fx-background-color: #5e9ae1;" text="Dialog" textFill="WHITE">
<font>
<Font size="25.0" />
</font>
</JFXButton>
</children>
</AnchorPane>
<JFXDialog fx:id="dialog">
<JFXDialogLayout>
<body>
<Label>This is a DIALOG!</Label>
</body>
<actions>
<JFXButton fx:id="acceptButton">ACCEPT
</JFXButton>
<JFXButton fx:id="declineButton">DECLINE
</JFXButton>
</actions>
</JFXDialogLayout>
</JFXDialog>
</children>
</StackPane>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment