How to specify tab location to make it visible in the bottom with Java?


Use the setTabPlacement() method to set the tab location. To make it visible in the bottom, use the BOTTOM constant −

JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);

The following is an example to specify tab location to make it visible in the bottom −

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("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.setTabPlacement(JTabbedPane.BOTTOM);
      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

Updated on: 30-Jul-2019

92 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements