Skip to content

Custom Notifications

Samuel Pfrommer edited this page May 6, 2017 · 5 revisions

JCommunique provides support for custom Notifications. Look at TextNotification or CustomNotification for an example. The simplest way to make your own Notification is to extend WindowNotification or BorderLayoutNotification. Both of these use Java Swing.

Making the Notification

To extend WindowNotification, you should supply a JPanel to the parent WindowNotification using setPanel(panel). This will allow the WindowNotification to handle the WindowTheme. Of course, your specific Notification will have to handle other types of themes. For instance, if there is text on the Notification, you should supply a setTextTheme() and invoke this in the NotificationBuilder.

Extending BorderLayoutNotification will simplify everything by managing a JPanel with a BorderLayout for you; all you have to call is addComponent(component) and removeComponent(component).

Modifying the factory

Now, to build the new Notification, you will have to register the Notification with the NotificationFactory. For this, you will have to supply a Class identifier and the NotificationBuilder with the corresponding generic Notification, which you must implement (factory.addBuilder(NewNotification.class, new NewNotification.CustomBuilder())). Later, you can build a Notification using factory.build(NewNotification.class, "arg1", 123). See the examples for more information.

Clone this wiki locally