1

I want to click a button in order to make a popup window appear with a tableview element inside it. Can anyone tell me how to do it?

Thanks in advance.

Salek
  • 449
  • 1
  • 10
  • 19
Bipin Bhandari
  • 652
  • 4
  • 9
  • 23

2 Answers2

13

This is the code for simple popup window in JavaFX. Hope this helps.

public class PopupExample extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(final Stage primaryStage) {
        primaryStage.setTitle("Popup Example");
        final Popup popup = new Popup();
        popup.setX(300);
        popup.setY(200);
        popup.getContent().addAll(new Circle(25, 25, 50, Color.AQUAMARINE));

        Button show = new Button("Show");
        show.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                popup.show(primaryStage);
            }
        });

        Button hide = new Button("Hide");
        hide.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                popup.hide();
            }
        });

        HBox layout = new HBox(10);
        layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
        layout.getChildren().addAll(show, hide);
        primaryStage.setScene(new Scene(layout));
        primaryStage.show();
    }
}
Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
Milan Pal Singh
  • 146
  • 1
  • 6
1

What kind of popup window do you need? Implemented with using a new Stage or Popup control? JavaFX has a control named Popup, read about it to see does it meet your needs. An entry point for Stage version could be Dialog with CLOSE button.

Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
  • i want to use with the pop up control. Just for time being i implemented this as a stage but its not looking very cool. so if you can help me with pop up control. It would b grt help. – Bipin Bhandari May 11 '12 at 05:25