I have a strange behaviour with a basic JTabbedPane: each time I add a new tab, the JtabbedPane is growing even if each component is the same size. I was expecting that the JTabbedPanel will be the size of the biggest component when inside a BorderLayout.
Try this code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main
{
public static void main(String args[])
{
Runnable runner = new Runnable()
{
public void run()
{
final JFrame frame = new JFrame("Tabbed Pane Sample");
JPanel panel = new JPanel(new BorderLayout());
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTabbedPane tabbedPane = new JTabbedPane();
panel.add(tabbedPane, BorderLayout.NORTH);
JButton add = new JButton("Add");
add.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tabbedPane.addTab("New tab", new JLabel("Same label"));
}
});
panel.add(add, BorderLayout.SOUTH);
JTextArea text = new JTextArea("Alea jacta est, press the buttom 6 times if you can");
panel.add(text, BorderLayout.CENTER);
frame.setSize(400, 150);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}