Welcome to the user guide for the JTipOfTheDay Swing Component. This guide will help to get you started with this powerful component, designed to provide you with a convenient way of getting "Tip Of The Day" functionality into your Java applications.
![]()
There are 2 ways to create the JTipOfTheDay: both constructors need a JFrame - this should be the main frame of your application. The second constructor allows you to specify the location of the tips file. This is relative to the current working directory of the JRE, or the root of your JAR file, depending on how you package your application.
JTipOfTheDay myTips = new JTipOfTheDay(mainFrame); or
JTipOfTheDay myTips = new JTipOfTheDay(mainFrame,"/config/tips.txt");

There are 7 main areas of the JTipOfTheDay dialog that you can configure - all of this configuration should be performed before the Tips window is displayed.
To add an icon to the icon panel, you can use the following method:
myTips.addIconImage(new ImageIcon(JTipOfTheDay_Demo.class.getResource("/images/LightBulbOff.gif")).getImage());
This method of loading images will also work if you package your application into a JAR file. You can add multiple images using the same method.
Additionally, you can set the position of the icon in the panel, using one of three constants defined in the JTipOfTheDayClass. For example:
myTips.setIconPosition(JTipOfTheDay.ICON_TOP);
myTips.setIconPosition(JTipOfTheDay.ICON_THIRD);
myTips.setIconPosition(JTipOfTheDay.ICON_MIDDLE);
To change the icon being displayed on the icon panel, use the following method - it will display the next icon in the list, wrapping round to the first image when the last image is displayed. This can be used to create an animated icon panel, as shown in the demo application.
myTips.displayNextIconImage();
Finally, you can set the width of the icon panel. This allows you to resize the panel based o the width of the images you are loading in.
myTips.setIconWidth(100);
You set the title of the window using the following method:
myTips.setWindowTitle("Insert Title Here...");
The header title is a little more configurable than the window title - you can also change the font.
myTips.setHeaderTitle("New Header Title");
myTips.setHeaderFont(new Font("Helvetica", Font.BOLD,18));
This is where the tips themselves will be displayed. You can alter the tips text font, and specify if a scrollbar should appear for viewing larger tips:
myTips.setTipTextFont(new Font("Helvetica",Font.PLAIN,12));
myTips.setScrollPaneVisible(true);
Although you cannot configure the display of this checkbox directly, by calling the following method you can set whether or not it is checked. NOTE: setting it to false will cause the tips window to not be displayed.
myTips.setShowOnStartup(true);
The "Previous Tips" button is not displayed by default. If you want to enable this button, use the following method:
myTips.setPreviousButtonEnabled(true);
Although the display of the tip counter cannot be modified, you can set the tip that will be shown when the tips window is displayed. This would typically be stored in some kind of properties file by an application, and read upon startup. Tip indexes start at 1, rather than zero.
myTips.setInitialTipIndex(initialTipIndex);
Once your Tip Of The Day window has been configured, you are ready to display it to your users. This is done using just one simple method call.
myTips.showTips();
This will construct the tips window, and check whether or not it should be displayed - you can alter this value by calling this method:
myTips.setShowOnStartup(false);
This value could also be read from a properties file on startup, and in the next section we will show you how to register for changes to the "Show tips at startup" value.
By creating and registering a TipChangeListener, your program can listen for when the user clicks on either the "Previous Tip" or "Next Tip" buttons. When one of these events occurs, you can read the current tip index and store it, to be read next time your application starts.
Here is a simple example of how to use this feature:
myTips.addTipChangeListener(new TipChangeListener() {
public void tipIndexChanged(int index) {
// Store the index value in a properties file
}
});
Similarly, you can register for user changes to the "Show tips at startup" checkbox, using a TipShowListener. This will give you a boolean value - TRUE if the tips window should be shown on startup.
Here is a simple example of how to use this feature:
myTips.addTipShowListener(new TipShowListener() {
public void tipShowChanged(boolean changed) {
// Could be output to a properties file or similar,
// then call myTips.setShowOnStartup() with that value
}
});
The tips file is just a plain ASCII text file. Each tip should be on a single line, and line breaks can be forced by including the characters "\n" on that line. Note please that word-wrapping is active on the tips panel, so you only need to force line breaks for new paragraphs.
An example tips file is included with the demo application, so that is a good place to look for inspiration on writing your own tips, and how to use the line breaks.
Anti-aliased text draws the various elements of the JTipOfTheDay with smooth edges, vastly improving the look of the component. To enable this feature, use the following code:
JTipOfTheDay myTips = new JTipOfTheDay(); myTips.setAntiAliased(true);
And to disable the anti-aliasing:
myTips.setAntiAliased(false);
There is one additional method to allow you to query the current state of the anti-aliasing:
boolean isAA = myTips.isAntiAliased();
The Icon Panel can be assigned a background renderer, as provided by the Renderers set of classes also from SyGem Software. For example, to achieve a "Metal-shaded" look, a gradient background renderer could be used:
BackgroundRenderer back = new GradientBackgroundRenderer(new Color(255,255,255),new Color(211,207,196)) myTips.setIconPanelRenderer(back);
Like most of the SyGem Swing Components, the JTipOfTheDay has been created as a JavaBean, making it simple to use in conjunction with your favourite Java IDE. All you need to do is import the JTipOfTheDay JAR file into the IDE, and it should become available in the component palette of your choice. Please refer to the instruction manual for your IDE for more details on using and importing JavaBeans.
![]()
I hope you enjoy using the JTipOfTheDay - if you need any help using this or any of our components, please email us: jtipoftheday@sygem.com