Skip to main content

APIzation: Replication Package

[Q#14168064][A#14168238] How to create a JavaFX dialog?

https://stackoverflow.com/q/14168064

I need to create a dialog in JavaFX. I know that I can make the Stage behave like a dialog by modifying modal, owner and resizable properties. But how do I hide the "minimize" and "maximize" buttons from the Stage window? Typical dialogs only have the "close" button.

Answer

https://stackoverflow.com/a/14168238

Under Windows 7, initializing to StageStyle.UTILITY before you show the window will create a window with only a close button and no minimize or maximize button: If you would like a complete set of basic JavaFX dialogs I would recommend the JavaFX UI sandbox dialogs. The JavaFX UI Sandbox was not created by me and is not hosted on my site (source is hosted by Oracle). I requested Oracle to document the sandbox dialog API. If you like, you may vote for or comment on the request. Makery's blog has some minimal 3rd party documentation of the sandbox dialogs, including basic usage examples as well as a backport of the dialog portion to JavaFX 2.2. Update The JavaFX UI Sandbox has been superseded by the ControlsFX project. Update Java 8u40 will include JavaFX dialogs built into the core platform APIs. You can try an early access release of Java8u40. The relevant class is javafx.scene.control.Dialog and it's related subclasses such as javafx.scene.control.Alert (the Alert class is for showing standard dialogs which are similar to Swing's JOptionPane class - so you don't need to use JOptionPane to get out of the box standard dialog functionality). Makery wrote a new blog tutorial for dialog functionality provided in Java 8u40. Related Questions

APIzation

Stage dialog = new Stage();
dialog.initStyle(StageStyle.UTILITY);
Scene scene = new Scene(new Group(new Text(25, 25, "Hello World!")));
dialog.setScene(scene);
dialog.show();
package com.stackoverflow.api;

public class Human14168238 {

  public static void createDialog(String pTextToShow) {
    Stage dialog = new Stage();
    dialog.initStyle(StageStyle.UTILITY);
    Scene scene = new Scene(new Group(new Text(25, 25, pTextToShow)));
    dialog.setScene(scene);
    dialog.show();
  }
}

package com.stackoverflow.api;

import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 * How to create a JavaFX dialog?
 *
 * @author APIzator
 * @see <a href="https://stackoverflow.com/a/14168238">https://stackoverflow.com/a/14168238</a>
 */
public class APIzator14168238 {

  public static void createDialog() throws Exception {
    Stage dialog = new Stage();
    dialog.initStyle(StageStyle.UTILITY);
    Scene scene = new Scene(new Group(new Text(25, 25, "Hello World!")));
    dialog.setScene(scene);
    dialog.show();
  }
}