In this section, you will learn how to set an icon with text in a column head of JTable component. But what is icon?
Icon: This is a graphical user interface (GUI). An image or picture available on the screen that helps you to identify file, folder, directory and window etc.
Description of program:
First of all this program creates a JTable containing some data and column with column header. After that you will set the icons in column header. For this you will need an image or icon that have '.gif' extension. Here you will see the SetIcon method applied for setting the icon with text in column header. This method uses the setHeaderRenderer and setHeaderValue methods that helps you setting the icon and text in column header. After doing entire process, you will get the first and second column header having icon with text.
Description of code:
setText():
This is the method that is used to set the given text in specified location.
setIcon():
This method helps you to set the given icon on the specified location.
Here is the code of program:
import javax.swing.*;
|
Output of program:
Before setting an icon:
After setting an icon with text:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Setting an Icon with Text in a Column Head of JTable
Post your Comment