Hi all,
I have a set of panels that a user flips through, which I can implement either as a set of JPanels in a CardLayout or as a JTabbedPane with the tabs hidden -- it's no difference to me.
If all the panels have been instantiated, the current panel is always the size of the largest panel in the set. So if the current panel is significantly smaller than the largest panel, there's a bunch of unnecessary white space.
Is there any way to set things up so that the the currently visible panel is always that size that it would normally want to be (i.e. if it weren'tpart of a CardLayout/JTabbedPane)?
Thanks!
Sam
Below is a self-contained example using a JTabbedPane, but the same applies to a JPanel with CardLayout.
import java.awt.*;
import javax.swing.*;
public class SwingTester extends JFrame{
public SwingTester(){
JTabbedPane tabbedPane = new JTabbedPane();
JComponent smallComponent = new JLabel("Test");
tabbedPane.addTab("Small tab", smallComponent);
JComponent largeComponent = new JLabel("Test ... Test ... Test");
largeComponent.setBorder(BorderFactory.createLineBorder(Color.RED, 20));
tabbedPane.addTab("Large tab", largeComponent);
getContentPane().add(tabbedPane);
}
public static void main(String[] args){
SwingTester st = new SwingTester();
st.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
st.pack();
st.setVisible(true);
}
}