Creating a nested JTabbedPane

The following example nests JTabbedPanes recursively until 10 levels deep:

import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.beans.*;
 
public class Main extends JFrame {
 
   public Main() {
      getContentPane().setLayout(new BorderLayout());
      JTabbedPane tabbedPane = new JTabbedPane();
 
      getContentPane().add(BorderLayout.CENTER, tabbedPane);
  
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
            System.exit(0);
         }
      });
 
      setTitle("JTabbedPane Nested Demonstration");
      setSize(new Dimension(400, 400));
 
      createTab(tabbedPane, 0);
   }
 
   protected void createTab(JTabbedPane jtp, int ct) {
      if (ct > 10) return;
      JTabbedPane tp = new JTabbedPane();
      tp.setTabPlacement(getNextOrientation(jtp.getTabPlacement()));
      jtp.addTab("TabLevel #" + ct, tp);
      createTab(tp, ct+1);
   }
 
   private int getNextOrientation(int tabPlacement) {
      if (tabPlacement == JTabbedPane.TOP) return JTabbedPane.RIGHT;
      if (tabPlacement == JTabbedPane.RIGHT) return JTabbedPane.BOTTOM;
      if (tabPlacement == JTabbedPane.BOTTOM) return JTabbedPane.LEFT;
      else return JTabbedPane.TOP;
   }
 
   public static void main(String []args) {
      Main main = new Main();
      main.show();
   }
}