Thursday, February 23, 2012

Dialog with CLOSE button

Last article, Create Dialog using Stage, demonstrate how to create our dialog by instancing object from Stage class. Normally, we have a button to close the dialog. In this article, a okButton is implemented to close the dialog.
Dialog with CLOSE button
package javafx_mydialog;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBoxBuilder;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;

* @web
public class JavaFX_MyDialog extends Application {

* @param args the command line arguments
public static void main(String[] args) {

public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Open Dialog");
btn.setOnAction(new EventHandler<ActionEvent>() {

public void handle(ActionEvent event) {
final Stage myDialog = new Stage();

Button okButton = new Button("CLOSE");
okButton.setOnAction(new EventHandler<ActionEvent>(){

public void handle(ActionEvent arg0) {


Scene myDialogScene = new Scene(VBoxBuilder.create()
.children(new Text("Hello! it's My Dialog."), okButton)
.padding(new Insets(10))


StackPane root = new StackPane();
primaryStage.setScene(new Scene(root, 300, 250));;

- Modality of Stage

No comments:

Post a Comment