In this section, you will learn how to set the tool tip text for items present in the JList component of the Java Swing. Tool Tip text is the help text of any component for user. When you rest the mouse cursor on the component then at that point a message which small font and yellow background stay there for few seconds. This text show the information about that component.
This program has used the tool tip text for items present in the JList component in Java Swing. In this program, you can add more and more items. You can enter the item name in the text box and click on the "Add" button. When you move the mouse pointer around the items in the list, it shows the specific item name as a tool tip text like the following image:
Following are some methods and APIs are explained as follows:
This is the class of javax.swing.*; package of Java Swing. This class is used to create scroll bar (Horizontal or Vertical) for any component. This program has used this for creating scroll bar for the text area. It creates scroll bar using it's constructor which holds the component name for which the scroll bar has to be created.
This is the class of javax.swing.*; package of Java. This class is used to create a list model which is helpful for adding items for the list. This class has used own method to add items in the list.
This is the method of the MultiListUI class which is imported from the javax.swing.plaf.multi.*; package of Java. This method locate the item to the index where the mouse pointer points. This method takes a integer value for locating item from the list according to the given point.
This is the method of JList class which holds the list of item which are shown in the JList component of Java Swing. It returns the list model.
This is the method of DefaultListModel class which gets the item from the returned list model by getModel() method according to the given integer index no. as parameter.
This is the method of DefaultListModel class which adds the item into the list.
Here is the code of the program:
Posted on: April 14, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles