Thursday, February 23, 2012

Create Dialog using Stage

There are no standard Dialog in JavaFX 2.0. You can create your own dialog using javafx.stage.Stage.
Create Dialog using Stage
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) {
Stage myDialog = new Stage();

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


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

- Dialog with CLOSE button

No comments:

Post a Comment