- 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
Can we display a JTabPane with TextArea in one of the tabs with Java
Yes, we can display a JTabPane with TextArea in one of the tabs. For that, let us first create a JTabbedPane component −
JTabbedPane tabbedPane = new JTabbedPane();
Now, create a text area you want to set under one of the tabs −
JTextArea text = new JTextArea(100,100);
Now, set panels for the tabs. Under one of them, set the text area we created above as shown below −
panel2 = new JPanel(); panel2.add(text); panel3 = new JPanel(); panel4 = new JPanel(); panel5 = new JPanel(); panel6 = new JPanel(); panel7 = new JPanel(); panel8 = new JPanel();
Now, one by one create different tabs and set the panels for each −
tabbedPane.addTab("Laptop", panel1); tabbedPane.addTab("Desktop ", panel2); tabbedPane.addTab("Notebook", panel3); . . .
The following is an example to display TextArea in one of the tabs −
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.orange); tabbedPane.setForeground(Color.white); 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); frame.add(tabbedPane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600,350); frame.setVisible(true); } }
Output
Now, since we have set a TextFileld in the 2nd tab, therefore on clicking the “Desktop” i.e. 2nd tab, the following would be visible −
- Related Articles
- How can we display all modules with classloaders in Java 9?
- How can we change the default font of the JTabbedPane tabs in Java?
- How can we insert multiple tabs into a single JTabbedPane in Java?
- How can we add new tabs to JTabbedPane from a JMenu in Java?
- Display all the titles of JTabbedPane tabs on Console in Java
- Switch tabs using Selenium WebDriver with Java.
- Can we sort a list with Lambda in Java?
- Can we change the Cursor with Java Swing?
- How can we compare a StringBuilder with StringBuffer in Java?
- Can we use Comparator with list in Java?
- How can we display the line numbers inside a JTextArea in Java?
- Can we use Switch statement with Strings in java?
- Can we set JOptionPane with predefined selection in Java?
- How can we create a JPopupMenu with a sub menu in Java?
- Can we get the HTTP Response Code in Selenium with Java?

Advertisements