JavaFX: what is the best way to display a simple message?

ceklock

In my application I need to display a warning/info message, but I don't know a simple way to do that because there is no JOptionPane or similar component on JavaFX.

There is a Popup class, but you have to set many parameters to get a decent layout/position/background color/etc for a simple message... So I want to know if there is a simple, already implemented component to display messages, maybe in a third party library if JavaFX does not offer anything decent.

Thanks in advance for any help/hints.

ceklock

ControlsFX is JavaFX 8 so I can't use it, and the other alternatives are almost the same level of complexity of what I was going to do. So I implemented my own methods to display an info/warning message using a Popup.

Here is the source code of what I implemented. Just some tweaks to show the Popup centered on the window, use CSS and hide when the user clicks on it.

public static Popup createPopup(final String message) {
    final Popup popup = new Popup();
    popup.setAutoFix(true);
    popup.setAutoHide(true);
    popup.setHideOnEscape(true);
    Label label = new Label(message);
    label.setOnMouseReleased(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            popup.hide();
        }
    });
    label.getStylesheets().add("/css/styles.css");
    label.getStyleClass().add("popup");
    popup.getContent().add(label);
    return popup;
}

public static void showPopupMessage(final String message, final Stage stage) {
    final Popup popup = createPopup(message);
    popup.setOnShown(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent e) {
            popup.setX(stage.getX() + stage.getWidth()/2 - popup.getWidth()/2);
            popup.setY(stage.getY() + stage.getHeight()/2 - popup.getHeight()/2);
        }
    });        
    popup.show(stage);
}


CSS:

.popup {
    -fx-background-color: cornsilk;
    -fx-padding: 10;
    -fx-border-color: black; 
    -fx-border-width: 5;
    -fx-font-size: 16;
}


The pop-up message:

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

iPhone - What is the best way to display error message below UITextfield

From Dev

What is the best way to defer a Message?

From Dev

Is there a simple way to display hint texts in JavaFX?

From Dev

What is the best way to manage multithreading in JavaFX 8?

From Dev

What is the best way to display the result of this array

From Dev

what is the best way to display PDF in DIV or panel

From Dev

What is the best way to display menu in Laravel 5.1?

From Dev

what is the best way to display PDF in DIV or panel

From Dev

Is UILabel the best way to display a simple vertical bar graph in iOS?

From Dev

JavaFX what is the best way to update a massive amount of buttons at once?

From Dev

JavaFX what is the best way to update a massive amount of buttons at once?

From Dev

What is the best way to detect whether the objects are saved in javafx desktop application?

From Dev

What's the best practice/guideline to display a "please wait" message in Android?

From Dev

What is the best way to embed multiple payloads in the "Message" object in spring integration?

From Dev

What's the best way to check the first message that's received by the server?

From Dev

What is the best way to create simple filter functions in javascript?

From Dev

What is the best way test to test simple logout and automatically logout with Protractor

From Dev

What is the best way to create a simple slideshow into an Android project?

From Dev

What is the best way to offer people to install a script plus simple dependencies

From Dev

What's a good way to display text messages in JavaFX FXML?

From Dev

What is the best way to change the sprite used to display an object?

From Dev

What is the best way to display rich content in an iOS app?

From Dev

what is the best way to display long text in xaml for windows phone app

From Dev

What is the best way to display a price with a smaller $ sign on the left using CSS?

From Dev

What is the best way to display report without installing anything on client

From Dev

What is the best way to display conditional content in Blazor Components

From Dev

what is the best way to display long text in xaml for windows phone app

From Dev

What's the best way to organize a display list using AS3?

From Dev

What is the best way to display JSON response in HTML div?

Related Related

  1. 1

    iPhone - What is the best way to display error message below UITextfield

  2. 2

    What is the best way to defer a Message?

  3. 3

    Is there a simple way to display hint texts in JavaFX?

  4. 4

    What is the best way to manage multithreading in JavaFX 8?

  5. 5

    What is the best way to display the result of this array

  6. 6

    what is the best way to display PDF in DIV or panel

  7. 7

    What is the best way to display menu in Laravel 5.1?

  8. 8

    what is the best way to display PDF in DIV or panel

  9. 9

    Is UILabel the best way to display a simple vertical bar graph in iOS?

  10. 10

    JavaFX what is the best way to update a massive amount of buttons at once?

  11. 11

    JavaFX what is the best way to update a massive amount of buttons at once?

  12. 12

    What is the best way to detect whether the objects are saved in javafx desktop application?

  13. 13

    What's the best practice/guideline to display a "please wait" message in Android?

  14. 14

    What is the best way to embed multiple payloads in the "Message" object in spring integration?

  15. 15

    What's the best way to check the first message that's received by the server?

  16. 16

    What is the best way to create simple filter functions in javascript?

  17. 17

    What is the best way test to test simple logout and automatically logout with Protractor

  18. 18

    What is the best way to create a simple slideshow into an Android project?

  19. 19

    What is the best way to offer people to install a script plus simple dependencies

  20. 20

    What's a good way to display text messages in JavaFX FXML?

  21. 21

    What is the best way to change the sprite used to display an object?

  22. 22

    What is the best way to display rich content in an iOS app?

  23. 23

    what is the best way to display long text in xaml for windows phone app

  24. 24

    What is the best way to display a price with a smaller $ sign on the left using CSS?

  25. 25

    What is the best way to display report without installing anything on client

  26. 26

    What is the best way to display conditional content in Blazor Components

  27. 27

    what is the best way to display long text in xaml for windows phone app

  28. 28

    What's the best way to organize a display list using AS3?

  29. 29

    What is the best way to display JSON response in HTML div?

HotTag

Archive