Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hugoquinn2/fxpopup

FxPopup It is a javafx library for displaying notifications in a very simple way.
https://github.com/hugoquinn2/fxpopup

javafx library

Last synced: about 1 month ago
JSON representation

FxPopup It is a javafx library for displaying notifications in a very simple way.

Awesome Lists containing this project

README

        


FxPopup



Logo

FxPopup It is a javafx library for displaying notifications in a very simple way.

## Maven
```xml

io.github.hugoquinn2
fxpopup
0.1.0

```

## Getting started

FxPopup injects xml code into the JavaFx application to display notifications to the user, for this, the main container must be a StackPane, which is provided to the controller.

```java
// Basic load content
StackPane root = new StackPane();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/path/to/body.fxml"));
root.getChildren().add(fxmlLoader.load());
Scene scene = new Scene(root, 500, 500);

//Example use lib
FxPopup fxPopup = new FxPopup(root);
```
## Show Message

To display a message it is necessary to create a Message object, by default the messages will be displayed with the light theme Theme.LIGHT

```java
// Full Message.
Message exampleMessage = new Message(
"Title",
"Context",
MessageType.SUCCESS, // Message.INFO, Message.WARNING, Message.ERROR
10 // Duration seconds
);

// Message without context.
Message simpleMessage = new Message(
"Title",
MessageType.SUCCESS, // Message.INFO, Message.WARNING, Message.ERROR
10 // Duration seconds
);

fxPopup.add(exampleMessage);
fxPopup.add(simpleMessage);
```
### Change Theme

You can change the theme with the function fxPopup.setTheme(Theme.DARK), this will apply to all messages

```java
fxPopup.setTheme(Theme.DARK);
```

## Add action event to message

The functionalities of a message are not limited to simple plain text, it requires important actions. These actions can be added directly to the Message with the function: message.setAction(EventType, EventHandler).

```java
// Example mouse clicked on message action.
message.setAction(MouseEvent.MOUSE_CLICKED, event -> {
// Custom Action
...
});
```

## Add custom theme.

If you don't like the themes already provided, it is possible to apply personal themes with the function, message.setCss(Resource).

```java
// Example style custom.
String css = Objects.requireNonNull(getClass().getResource("/resource/path/style.css")).toExternalForm();
message.setCss(css);
```

### Default message structure.

```ascii
VBox (#messageBody)
├── HBox
│ ├── Pane (#alertPane)
│ ├── VBox
│ │ ├── Label (#messageTitle)
│ │ └── Label (#messageContext)
│ └── Button (#buttonCloseMessage)

```