

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 set TabLayout Policy to JTabbedPane in Java when all the tabs does not fit in a single run
To set TabLayout Policy to JTabbedPane in Java when all the tabs does not fit in a single run, use the method setTabLayoutPolicy() −
JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
Above we have set the constant to be SCROLL_TAB_LAYOUT, which is a tab layout policy for providing a subset of available tabs when all the tabs will not fit within a single run.
The following is an example −
package my; import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Devices"); JTabbedPane tabbedPane = new JTabbedPane(); JPanel panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8; panel1 = new JPanel(); panel2 = new JPanel(); 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.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); 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(500,350); frame.setVisible(true); } }
The output is as follows. Now you can see all the tabs does not fit, therefore a navigation is visible to display all other tabs on the right −
Now when you will click on the right navigation, all the other tabs will be visible −
- Related Questions & Answers
- How can we insert multiple tabs into a single JTabbedPane in Java?
- How to set the location of the Tabs in a JTabbedPane Container to the left in Java?
- Display all the titles of JTabbedPane tabs on Console in Java
- How to enable Scrolling Tabs in a JTabbedPane Container
- How to set the background color of a single tab in a JTabbedPane Container with Java?
- How can we add new tabs to JTabbedPane from a JMenu in Java?
- How can we change the default font of the JTabbedPane tabs in Java?
- Java program to set the color of a single tab’s text in a JTabbedPane Container
- How to customize how a JTabbedPane looks in Java?
- How to set all values in a single column MySQL Query?
- How to add a Tab in JTabbedPane with Java?
- How to set fit webview screen in android?
- Is there a case when finally block does not execute in Java?
- How to set all outline properties in a single declaration with JavaScript?
- How to disable a Tab in a JTabbedPane Container with Java?
Advertisements