- 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
How to add a Tab in JTabbedPane with Java?
Let us first create a JTabbedPane −
JTabbedPane tabbedPane = new JTabbedPane();
Create some panels −
JPanel panel1, panel2, panel3, panel4, panel5; panel1 = new JPanel(); panel2 = new JPanel(); panel3 = new JPanel(); panel4 = new JPanel(); panel5 = new JPanel();
Now, add tabs using the addTab() method and set the panels as well in which the tabs would be visible −
tabbedPane.addTab("PHP", panel1); tabbedPane.addTab("Blockchain ", panel2); tabbedPane.addTab("Matlab", panel3); tabbedPane.addTab("JSP ", panel4); tabbedPane.addTab("Servlet", panel5);
The following is an example to add a tab in JTabbedPane −
package my; import javax.swing.*; import java.awt.*; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Technologies"); JTabbedPane tabbedPane = new JTabbedPane(); JPanel panel1, panel2, panel3, panel4, panel5; panel1 = new JPanel(); panel2 = new JPanel(); panel3 = new JPanel(); panel4 = new JPanel(); panel5 = new JPanel(); tabbedPane.addTab("PHP", panel1); tabbedPane.addTab("Blockchain ", panel2); tabbedPane.addTab("Matlab", panel3); tabbedPane.addTab("JSP ", panel4); tabbedPane.addTab("Servlet", panel5); frame.add(tabbedPane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(550,350); frame.setVisible(true); } }
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 can we highlight the selected tab of a JTabbedPane in Java?
- Insert a tab after the first tab of a JTabbedPane container
- How can we add new tabs to JTabbedPane from a JMenu in Java?
- How to customize how a JTabbedPane looks in Java?
- How to add separator in a ToolBar with Java?
- How to specify tab location to make it visible in the bottom with Java?
- How to get the Tab Size of a JTextArea in Java?
- C Sharp with Selenium - How to Switch one tab to another tab in Csharp Selenium?
- How can we insert multiple tabs into a single JTabbedPane in Java?
- How to enable Scrolling Tabs in a JTabbedPane Container
- Java Program to display JTabbedPane on the right
- How to add components with a Relative X Position in Java
- How to set the location of the Tabs in a JTabbedPane Container to the left in Java?

Advertisements