- 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
Insert a tab after the first tab of a JTabbedPane container
We are inserting a tab just after the first tab by using the index value 1. Here, index 1 would be location 2nd i.e. just after the first tab of the JTabbedPane container.
The following is an example to insert a tab after the first tab −
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.blue); tabbedPane.setForeground(Color.white); tabbedPane.addTab("Tablet", panel1); tabbedPane.addTab("Alexa ", panel2); tabbedPane.addTab("Laptop", panel3); tabbedPane.addTab("Desktop ", panel4); tabbedPane.addTab("Notebook", panel5); tabbedPane.addTab("Echo ", panel6); tabbedPane.addTab("Notebook", panel7); tabbedPane.addTab("iPad", panel8); JLabel label = new JLabel("Kindle"); tabbedPane.insertTab("Kindle", new ImageIcon("icon.png"), label, "Kindle", 1); frame.add(tabbedPane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600,270); frame.setVisible(true); } }
The output is as follows. Here, we can see our new tab “Kindle”, just after the first tab −
Output
- Related Articles
- How to disable a Tab in a JTabbedPane Container with Java?
- How to set the background color of a single tab in a JTabbedPane Container with Java?
- How to add a Tab in JTabbedPane with Java?
- How can we highlight the selected tab of a JTabbedPane in Java?
- Set the width of a tab character with CSS
- Setting Tab Sizes in HTML with CSS tab-size Property
- With JavaScript RegExp search a tab character.
- How to Create a Tab Image Gallery?
- CSS tab-size Property
- Bootstrap .tab("show") method
- How to get the Tab Size of a JTextArea in Java?
- With JavaScript RegExp search a vertical tab character.
- How to enable Scrolling Tabs in a JTabbedPane Container
- How to set the tab order in a Tkinter application?
- Fade in tab with Bootstrap

Advertisements