Tips are retrieved from the {@link org.jdesktop.swingx.tips.TipOfTheDayModel}. In the most common usage, a tip (as returned by {@link org.jdesktop.swingx.tips.TipOfTheDayModel.Tip#getTip()}) is just a String
. However, the return type of this method is actually Object
. Its interpretation depends on its type:
Component
is displayed in the dialog. Icon
is wrapped in a JLabel
and displayed in the dialog. String
by calling its toString
method. The result is wrapped in a JEditorPane
or JTextArea
and displayed. JXTipOfTheDay
finds its tips in its {@link org.jdesktop.swingx.tips.TipOfTheDayModel}. Such model can be programmatically built using {@link org.jdesktop.swingx.tips.DefaultTipOfTheDayModel}and {@link org.jdesktop.swingx.tips.DefaultTip} butthe {@link org.jdesktop.swingx.tips.TipLoader} provides a convenient method tobuild a model and its tips from a {@link java.util.Properties} object.
Example:
Let's consider a file tips.properties with the following content:
tip.1.description=This is the first time! Plain text. tip.2.description=<html>This is <b>another tip</b>, it uses HTML! tip.3.description=A third one
To load and display the tips: Properties tips = new Properties(); tips.load(new FileInputStream("tips.properties")); TipOfTheDayModel model = TipLoader.load(tips); JXTipOfTheDay totd = new JXTipOfTheDay(model); totd.showDialog(someParentComponent);
Additionally, JXTipOfTheDay
features an option enabling the end-user to choose to not display the "Tip Of The Day" dialog. This user choice can be stored in the user {@link java.util.prefs.Preferences} but JXTipOfTheDay
alsosupports custom storage through the {@link org.jdesktop.swingx.JXTipOfTheDay.ShowOnStartupChoice} interface.
Preferences userPreferences = Preferences.userRoot().node("myApp"); totd.showDialog(someParentComponent, userPreferences);
In this code, the first time showDialog is called, the dialog will be made visible and the user will have the choice to not display it again in the future (usually this is controlled by a checkbox "Show tips on startup"). If the user unchecks the option, subsequent calls to showDialog will not display the dialog. As the choice is saved in the user Preferences, it will persist when the application is relaunched.
@see org.jdesktop.swingx.tips.TipLoader
@see org.jdesktop.swingx.tips.TipOfTheDayModel
@see org.jdesktop.swingx.tips.TipOfTheDayModel.Tip
@see #showDialog(Component,Preferences)
@see #showDialog(Component,ShowOnStartupChoice)
@author Frederic Lavigne
|
|
|
|