Daytron / SimpleDialogFX

Lightweight dialog API for JavaFX.
https://daytron.github.io/SimpleDialogFX/
MIT License
21 stars 2 forks source link

SimpleDialogFX

Easy to use lightweight dialog library for JavaFX applications.

Contents


Features

[back to top]

Dialogs

[back to top]

Information Dialog

Confirmation Dialog

Confirmation Alternative 1 Dialog

Confirmation Alternative 2 Dialog

Warning Dialog

Error Dialog

Input Text Dialog

Exception Dialog

Color Themes

[back to top]

If none of those colors hook you, try mix and match various color styles.

Gloss Series

Gloss Series

Linear Fade Left Series

Linear Fade Left Series

Linear Fade Right Series

Linear Fade Right Series

Opaque Series

Opaque Series

Generic Style

Generic Style

Installation

[back to top]

SimpleDialogFX is available in Maven Central. To start using, simply add the following elements to your pom.xml file:

<dependency>
  <groupId>com.github.daytron</groupId>
  <artifactId>SimpleDialogFX</artifactId>
  <version>2.2.0</version>
</dependency>

Usage

[back to top]

Overview

[back to top]

A dialog consists of the following areas shown in the figure below:

Dialog overview

Construction

[back to top]

To create a dialog, you only have to create a new Dialog object. For example, a confirmation dialog would look like this:

Dialog dialog = new Dialog(
                DialogType.CONFIRMATION,
                "Confirm Action",
                "Are you sure?");
dialog.showAndWait();

For an exception dialog:

Dialog dialog = new Dialog(exception);
dialog.showAndWait();

Retrieving a response::

DialogResponse response = dialog.getResponse();

Another example:

Dialog dialog = new Dialog(
                DialogType.CONFIRMATION,
                "This is a sample title",
                "Confirm Action",
                "Are you sure?");
dialog.showAndWait();

if (dialog.getResponse() == DialogResponse.YES) {
    // Rest of the code
}

Result:

Result Example Dialog


For the complete list of constructors, see Javadoc.

Undecorated

[back to top]

For an undecorated window style approach, simply use the DialogStyle option, UNDECORATED in the constructor.

Dialog dialog = new Dialog(
                DialogType.CONFIRMATION,
                DialogStyle.UNDECORATED,
                "Confirm Action",
                "Are you sure?");
dialog.showAndWait();

Undecorated style Dialog


Headless

[back to top]

For a more simplistic approach, you may remove the header completely and show only the details section of the dialog. To choose a headless approach, simply use the DialogStyle option, HEADLESS in the constructor.

Headless style Dialog


Color Style

[back to top]

You can set the color style with HeaderColorStyle enum either via the constructor or through a method.

Via constructor:

Dialog(DialogType dialogType, HeaderColorStyle headerColorStyle, String header, String details) and

Dialog(DialogType dialogType, DialogStyle dialogStyle, String title, String header, HeaderColorStyle headerColorStyle, String details, Exception exception)

Via method:

setHeaderColorStyle(HeaderColorStyle headerColorStyle)

Font

[back to top]

Apply any style fonts using these methods:

setFontSize(int font_size)
setFontSize(int header_font_size, int details_font_size)
setFontFamily(String font_family)
setFontFamily(String header_font_family, String details_font_family)
setFont(String font_family, int font_size)
setFont(String header_font_family, int header_font_size, String details_font_family, int details_font_size)
 setHeaderFontSize(int font_size)
 setDetailsFontSize(int font_size)
 setHeaderFontFamily(String font_family)
 setDetailsFontFamily(String font_family)
 setHeaderFont(String font_family, int font_size)
 setDetailsFont(String font_family, int font_size)
Responses

[back to top]

The list of all available dialog responses:

Misc

[back to top]

UI components can be extracted, allowing you to customize the dialog as you see fit.

getHeaderLabel()    // The colored head label
getDetailsLabel()   // The label text below header
getTextField()      // For Input dialog's textfield
getExceptionArea() // For Exception dialog's textarea

In addition, the Dialog class itself is a subclass of the Stage class, so you can further customize the look and style of your dialogs.

Documentation

[back to top]

See Javadoc for more information.

Development

[back to top]

Want to contribute? Please do open up an issue for any bug reports, recommendation or feedback.

License

[back to top]

MIT