This swing toast notifications use for java desktop application gui swing with flatlaf
![sample dark](https://private-user-images.githubusercontent.com/58245926/246643649-71965d6a-1fd1-4ab4-b2d7-f7424b9c277e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5NDE4MzMsIm5iZiI6MTcyNTk0MTUzMywicGF0aCI6Ii81ODI0NTkyNi8yNDY2NDM2NDktNzE5NjVkNmEtMWZkMS00YWI0LWIyZDctZjc0MjRiOWMyNzdlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTEwVDA0MTIxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc5MTJjM2UwYmQ2YzUyMGUyNDBhZjIyNzExZjhmODYxZGNjOGI3ZTBhZDYwOWYzNjY1NTU4MmJiYTQzODBiMTcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.nTyrXqUfu3Sd4YOhWo76dwn0Vx0rU21ovpglIuy8AH8)
![sample light](https://private-user-images.githubusercontent.com/58245926/246643647-228a958d-ad02-41df-b1aa-b16f7d88deec.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5NDE4MzMsIm5iZiI6MTcyNTk0MTUzMywicGF0aCI6Ii81ODI0NTkyNi8yNDY2NDM2NDctMjI4YTk1OGQtYWQwMi00MWRmLWIxYWEtYjE2ZjdkODhkZWVjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTEwVDA0MTIxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYzYjdhNDJkNGM0NjQxOWZhZjVhMTNhYjQ4NTVmMjI2ZmFkNTU3ZTU4ZjZhN2IwYWI1NDQ0ZDViYmEwZWZlYTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Ossk2i7c2habsAfg07emRx7eg8jILJN3YcLj2xkeQ1c)
This library not available in maven, try use jar file, by copy to the root project /library/swing-toast-notifications-1.0.3.jar
<dependency>
<groupId>raven.toast</groupId>
<artifactId>swing-toast-notifications</artifactId>
<version>1.0.3</version>
<scope>system</scope>
<systemPath>${basedir}/library/swing-toast-notifications-1.0.3.jar</systemPath>
</dependency>
- Other library are use with this library
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf-extras</artifactId>
<version>3.4.1</version>
</dependency>
- Import flatlaf library and flatlaf extras to your project
- And Import swing toast notifications
(check jar file in library folder)
// Setup notifications with jfram
Notifications.getInstance().setJFrame(jfram);
// Show notifications
Notifications.getInstance().show(Notifications.Type.SUCCESS, Notifications.Location.TOP_CENTER, "Hello");
// Show notification with custom component
Notifications.getInstance().show(new JButton("My Custom Button"));
// Clear top right notifications
Notifications.getInstance().clear(Notifications.Location.TOP_RIGHT);
// Clear all notifications
Notifications.getInstance().clearAll();
// Install flatlaf look and feel to your application
FlatIntelliJLaf.setup();
// Notifications Type
public enum Type {
SUCCESS, INFO, WARNING, ERROR
}
// Notification Location
public enum Location {
TOP_LEFT, TOP_CENTER, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT
}
Create flatlaf file properties FlatLaf.properties
Toast.background=lighten(@background,5%)
Toast.outlineWidth = 1
Toast.success.foreground = rgb(53,198,203)
Toast.frameInsets = 15,15,15,15
Key | Description | Value Type | Default values |
---|---|---|---|
Toast.outlineWidth | int | 0 | |
Toast.iconTextGap | int | 5 | |
Toast.closeButtonGap | int | 5 | |
Toast.arc | int | 20 | |
Toast.horizontalGap | int | 10 | |
Toast.limit | -1 as unlimited | int | -1 |
Toast.duration | long | 2500 | |
Toast.animation | int | 200 | |
Toast.animationResolution | int | 5 | |
Toast.animationMove | int | 10 | |
Toast.minimumWidth | int | 50 | |
Toast.maximumWidth | -1 as not set | int | -1 |
Toast.shadowColor | Color | ||
Toast.shadowOpacity | 0 to 1f | float | 0.1f |
Toast.shadowInsets | Insets | 0,0,6,6 | |
Toast.useEffect | boolean | true | |
Toast.effectWidth | 0.5f as 50% | float | 0.5f |
Toast.effectOpacity | 0 to 1f | float | 0.2f |
Toast.effectAlignment | left, right | String | left |
Toast.effectColor | Color | ||
Toast.success.effectColor | Color | ||
Toast.info.effectColor | Color | ||
Toast.warning.effectColor | Color | ||
Toast.error.effectColor | Color | ||
Toast.outlineColor | Color | ||
Toast.foreground | Color | ||
Toast.background | Color | ||
Toast.success.outlineColor | Color | ||
Toast.success.foreground | Color | ||
Toast.success.background | Color | ||
Toast.info.outlineColor | Color | ||
Toast.info.foreground | Color | ||
Toast.info.background | Color | ||
Toast.warning.outlineColor | Color | ||
Toast.warning.foreground | Color | ||
Toast.warning.background | Color | ||
Toast.error.outlineColor | Color | ||
Toast.error.foreground | Color | ||
Toast.error.background | Color | ||
Toast.frameInsets | Insets | 10,10,10,10 | |
Toast.margin | Insets | 8,8,8,8 | |
Toast.showCloseButton | boolean | true | |
Toast.closeIconColor | Color |
// Using flatlaf extras to crate flat svg icon
// Use this code in main method
UIManager.put(ToastClientProperties.TOAST_INFO_ICON, new FlatSVGIcon("raven/toast/error.svg"));
Key | Description | Value Type |
---|---|---|
Toast.success.icon | Icon | |
Toast.info.icon | Icon | |
Toast.warning.icon | Icon | |
Toast.error.icon | Icon | |
Toast.closeIcon | Icon |
Visit flatlaf for more
version 1.0.1
- add properties
Toast.maximumWidth
- add properties
Toast.limit
- add method
void clearHold()
andvoid clearHold(Location location)
- add properties
version 1.0.1
- fixed notification style properties background