displaying messagebox using javafx

13,295

Solution 1

Update

Java 8u40 added official support for JavaFX dialogs and alerts (message boxes).

The built-in alerts cover most common message box usage scenarios.

The ControlsFX dialog implementation mentioned in the rest of this answer has been re-worked to function with the JavaFX dialog support in the JRE. Usually, it is sufficient to just use the built-in dialogs and alerts without a 3rd party library. However, for special cases such as wizard dialogs, etc., you may still wish to review and use the ControlsFX dialogs as they contain additional functionality over and above what can be found in the standard JavaFX dialogs.

Previous answer

I recommend upgrading to Java 8 and using the ControlsFX dialogs.

IMO the ControlsFX dialogs are better and (unlike the jfxmessagebox library), the ControlsFX library is under active development.

The ControlsFX dialog usage is also much better documented.

Sample code to display a ControlsFX message box:

Action response = Dialogs.create()
  .owner( isOwnerSelected ? stage : null)
  .title("You do want dialogs right?")
  .masthead(isMastheadVisible() ? "Just Checkin'" : null)
  .message( "I was a bit worried that you might not want them, so I wanted to double check.")
  .showConfirm();

dialog

Answers to additional questions regarding Java 8

Do you know how should I update to JavaFX 8 ?

On Windows, use the control panel "Add/Remove Programs" to remove your existing JDK installation. Then download the new JDK installed (e.g. jdk-8-windows-x64.exe) and install it.

My old application would not stop working after upgrading from JavaFX 2.2

Java is very good about maintaining compatibility between releases. Your existing application may need some tweaks if you used a lot of custom CSS, but other than that, it will probably work just fine - try it and see.

JavaFX was upgraded to 8 in jdk 8?

Yes. There is a changelog for JavaFX changes for Java 8.

Solution 2

here are most used javaFX dialogs.It might be helpful to you ....:-)

Share:
13,295
Admin
Author by

Admin

Updated on June 26, 2022

Comments

  • Admin
    Admin almost 2 years

    Has anyone used the following recently?

    I have included the jar file in my netbeans project

    and running the following code as mentioned in the documentation here:

     MessageBox.show(primaryStage,
    "Sample of error dialog.\n\nDialog option is below.\n[MessageBox.ICON_ERROR]",
    "Error dialog",
    MessageBox.ICON_ERROR);
    

    But nothing is happening in my code. At least I was expecting some window to pop up.

    I have imported jfx.messagebox.MessageBox; and javafx.stage.Window; in my code.

    I am using javafx version : 2.2.50