Very well then how about adding a title and another message?
JHollaManager.getInstance().addNotification(JHolla.create().setNotificationTitle("Hey Dude!").addMessage("Hello World!").addMessage("This is another message for this cute Notification."));
I see you now understand the pattern...Most of the methods return a reference to the object which you just simply use to do more on your jHolla notification. How about some more?
Let us create a jHolla Notification without a Timeout
JHollaManager.getInstance().addNotification(JHolla.create().setNotificationTitle("Test JHolla with Icon and without Timeout").addMessage(newJLabel("Simple Label for a test")).addMessage("A sample message for a sample notification which has no timeout. This notification would only be closed via the close button.").addIcon(newImageIcon(getClass().getResource("check.png"))).setTimeout(0));
From above, the timeout has been set to zero, meaning the notification can only be removed with the close button or programatically. Basically, any number less than or equal to zero will do this same job. Timeout is specified in milliseconds and the default timeout is 10 seconds.
We also got to add an icon to the Notification. No matter the size of the image, the image would be resampled to having a height of 24px and the proportional width.
Let us set a minimum width for our jHolla Notification and listen out for Events
JHollaManager.getInstance().addNotification(JHolla.create().setNotificationTitle("Test JHolla with JHollaListener").addMessage(newJLabel("Simple label")).setTimeout(30000).setMinWidth(400).addJHollaListener(newJHollaListener(){@Overridepublicvoidremoved(){log.append("JHolla Removed\n");}@OverridepublicvoidmouseExited(){log.append("Mouse Exited JHolla\n");}@OverridepublicvoidmouseEntered(){log.append("Mouse Entered JHolla\n");}@OverridepublicvoidcloseButtonClick(){log.append("JHolla Close Button clicked\n");}@Overridepublicvoidclicked(){log.append("JHolla Clicked\n");}}));
When you specify a String as the parameter to the JHolla addMessage method, a JTextArea is created with the text as its content.
The setMinWidth method basically sets the width of the very first JComponent added via the call to addMessage on the JHolla. In this case, the JLabel. If the argument to the addMessage method was a String, and it was the first added Message, the width would be applied to the JTextArea holding the text. This method is so rightly named cause JHolla has paddings (Empty Borders) around the first component and so the specified width would not be the exact width of the entire JHolla Notification.
JHollaListener is an inner class in the JHolla class and has all the methods listed above for your convenience. The call to addJHollaListener also returns a reference to the working JHolla object.
Let us create a custom remove button for our JHolla
finalJHollan=JHolla.create();JButtonremoveButton=newJButton("Remove Me");removeButton.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventevent){
n.remove();//remove/close notification}
});JHollaManager.getInstance().addNotification(n.setNotificationTitle("Test JHolla with Custom Close Button").addMessage("A sample message for a sample notification").addMessage("What next when you get to add more messages to this beautiful JHolla").addMessage("You can actually add infinite messages to this JHolla. I also hope your system's height is infinite...lol").setClosable(false).addComponent(removeButton).setMinWidth(400));
From the above, we first create our JHolla Notification, and then a remove button which will be one means to remove the Notification.
The setClosable method simply determines if JHolla should show a close button or not and does not mean JHolla would not be closed automatically by the default timeout.
You can add any JComponent via the addComponent method. The addMessage method has been defined for just a String and a JLabel. Using the addMessage to add a JLabel would remove some default formatting from the label, The font would be forced to plain, and the setOpaque method would be set to false. Using the addComponent retains most of the formatting you apply.
To summarize the function of this example above, the JHolla would be able to be removed by two means only - The default timeout and the added custom remove button.
Last edit: Richboy 2014-03-22
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Usage Guide
jHolla is quite easy to use and with just few lines of code you can create standard notifications. Let us get off the first and simple way...
Very well then how about adding a title and another message?
I see you now understand the pattern...Most of the methods return a reference to the object which you just simply use to do more on your jHolla notification. How about some more?
Let us create a jHolla Notification without a Timeout
From above, the timeout has been set to zero, meaning the notification can only be removed with the close button or programatically. Basically, any number less than or equal to zero will do this same job. Timeout is specified in milliseconds and the default timeout is 10 seconds.
We also got to add an icon to the Notification. No matter the size of the image, the image would be resampled to having a height of 24px and the proportional width.
Let us set a minimum width for our jHolla Notification and listen out for Events
When you specify a String as the parameter to the JHolla addMessage method, a JTextArea is created with the text as its content.
The setMinWidth method basically sets the width of the very first JComponent added via the call to addMessage on the JHolla. In this case, the JLabel. If the argument to the addMessage method was a String, and it was the first added Message, the width would be applied to the JTextArea holding the text. This method is so rightly named cause JHolla has paddings (Empty Borders) around the first component and so the specified width would not be the exact width of the entire JHolla Notification.
JHollaListener is an inner class in the JHolla class and has all the methods listed above for your convenience. The call to addJHollaListener also returns a reference to the working JHolla object.
Let us create a custom remove button for our JHolla
From the above, we first create our JHolla Notification, and then a remove button which will be one means to remove the Notification.
The setClosable method simply determines if JHolla should show a close button or not and does not mean JHolla would not be closed automatically by the default timeout.
You can add any JComponent via the addComponent method. The addMessage method has been defined for just a String and a JLabel. Using the addMessage to add a JLabel would remove some default formatting from the label, The font would be forced to plain, and the setOpaque method would be set to false. Using the addComponent retains most of the formatting you apply.
To summarize the function of this example above, the JHolla would be able to be removed by two means only - The default timeout and the added custom remove button.
Last edit: Richboy 2014-03-22