In this section, you will learn how to set colors for a tab in a tabbed pane container in Java Swing applications.
Set the Color of a Tab in a Tabbed Pane Container in Java
In this section, you will learn how to set colors for a tab in a tabbed pane container in Java Swing applications. Every tab and it's corresponding container can have different colors. Following screen shot of our example show the colorful tabs:
This program shows you how to set the color for each tab in the tabbed pane container. Background color and foreground color for the tab and it's corresponding container component are set using following methods:
setForegroundAt(int Index, Color.color_name):
This is the method of JTabbedPane class
is used to set the foreground color of the specified tab. This method takes two
argument in which, first is the index number of the tab which has to be colored
and another is the color which has to be set for the specific tab.
setBackgroundAt(int Index, Color.color_name):
This is the method of JTabbedPane class is used to set the background color of the specified tab. This method also takes
two argument, first is the index number of the tab which background has to be
colored and another is the color which has to be set for the background color of
the specified tab.
Here is the code of program:
import javax.swing.*;
|