We help IT Professionals succeed at work.

JTabbedPane Layout

sabi97
sabi97 asked
on
Hi,

What is the correct way to set the layout for a JTabbedpane? I'm getting errors when I use :

panel1.setLayout(new BorderLayout() );    
panel1.add(new JButton("Enter"),BorderLayout.SOUTH);

-----------------------------

Full code below :


import javax.swing.*;
import java.awt.event.*;
   
    public class Grads {
    public static void main(String args[]) {
            JFrame frame = new JFrame("Database");
       
   frame.addWindowListener(new
                      WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });
   
            JPanel panel1 = new JPanel();  
            JPanel panel2 = new JPanel();
            JPanel panel3 = new JPanel();
            JPanel panel4 = new JPanel();
           
           
 panel1.setLayout(new BorderLayout() );    
 panel1.add(new JButton("Enter"),BorderLayout.SOUTH);

            JTabbedPane jtp = new JTabbedPane();                        
            jtp.add("Search", panel1);
            jtp.add("Email", panel2);
            jtp.add("Management", panel3);
            jtp.add("Notes", panel4);
           
         
            frame.getContentPane().add(jtp);
            frame.setLocation(200, 200);
            frame.pack();
            frame.setVisible(true);
        }
    }

Comment
Watch Question

BRONZE EXPERT
Commented:
If you want the button below all the tabs, then put the tabbed pane into a JPanel with the desired layout.

Author

Commented:
Thanks! Worked well!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.