- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to set the color of a single tab’s text in a JTabbedPane Container
To set the the color of a single tab’s text, use the setForegroundAt() method. This gives an option to mention the index and the color. The index here is the index of the specific tab you want to color the text.
Let us first create a JTabbedPane −
JTabbedPane tabbedPane = new JTabbedPane();
Now, set the background color for one of the tabs with index 2 −
tabbedPane.setForegroundAt(2, Color.RED);
The following is an example wherein we will update the foreground color of a single tab in the JTabbedPane −
Example
package my; import javax.swing.*; import java.awt.*; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Devices"); JTabbedPane tabbedPane = new JTabbedPane(); JTextArea text = new JTextArea(100,100); JPanel panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8; panel1 = new JPanel(); panel2 = new JPanel(); panel2.add(text); panel3 = new JPanel(); panel4 = new JPanel(); panel5 = new JPanel(); panel6 = new JPanel(); panel7 = new JPanel(); panel8 = new JPanel(); tabbedPane.setBackground(Color.yellow); tabbedPane.setForeground(Color.black); tabbedPane.addTab("Laptop", panel1); tabbedPane.addTab("Desktop ", panel2); tabbedPane.addTab("Notebook", panel3); tabbedPane.addTab("Echo ", panel4); tabbedPane.addTab("Tablet", panel5); tabbedPane.addTab("Alexa ", panel6); tabbedPane.addTab("Notebook", panel7); tabbedPane.addTab("iPad", panel8); tabbedPane.setForegroundAt(2, Color.RED); frame.add(tabbedPane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(550,350); frame.setVisible(true); } }
Output
- Related Articles
- How to set the background color of a single tab in a JTabbedPane Container with Java?
- How to set the location of the Tabs in a JTabbedPane Container to the left in Java?
- How to disable a Tab in a JTabbedPane Container with Java?
- Java Program to set the Font and Color of some text in a JTextPane using Styles
- How to enable Scrolling Tabs in a JTabbedPane Container
- How to set TabLayout Policy to JTabbedPane in Java when all the tabs does not fit in a single run
- Insert a tab after the first tab of a JTabbedPane container
- How to set the color of a text with CSS
- How can we insert multiple tabs into a single JTabbedPane in Java?
- How to set the grid color of a table in Java?
- Java Program to set the height of only a single row in a JTable with multiple rows
- Set the color of the text decoration in CSS
- Java Program to display JTabbedPane on the right
- How to customize a button to set text and color in Android?
- How to set the color of the text-decoration with JavaScript?

Advertisements