i searched and searched and couldn’t find the answer to this. the JLayeredPane seems to not behave as it is documented. before i dug deeper i wanted to know if i am doing something wrong.
import java.awt.*;
import javax.swing.*;
public class JLayeredPaneTest {
JFrame frame;
JPanel container = new JPanel();
JPanel test = new JPanel();
JLayeredPane pane = new JLayeredPane();
/** Creates a new instance of RulerPanelTest */
public JLayeredPaneTest() {
setupFrame();
}
public static void main(String[] args) {
new JLayeredPaneTest();
}
private void setupFrame() {
frame = new JFrame( getClass().getName() );
frame.setBackground( new Color(255, 204, 204 ) );
frame.setSize( 640, 480 );
frame.setLayout( new BoxLayout( frame, BoxLayout.X_AXIS ));
frame.setContentPane( container );
container.setBorder( BorderFactory.createTitledBorder( "container" ));
container.add( test );
test.setBackground( Color.white );
test.setPreferredSize( new Dimension( 400, 250 ));
test.setBorder( BorderFactory.createTitledBorder( " test "));
test.add(pane );
pane.setBorder( BorderFactory.createTitledBorder("pane"));
pane.setBounds(0, 0, 300, 300 );
JLabel l = new JLabel("label");
l.setOpaque( true );
l.setBounds( 50, 50, 200, 200 );
pane.add( l );
System.out.println( pane.getSize() );
System.out.println(pane.getComponentCount() );
frame.setVisible( true );
}
}
it’s weird, because when i getSize() on the pane, it gives me a dimension.
the whole reason i’ve spent a long frustrating weekend trying to make this work is i need to create a timeruler out of JComponents: is maybe there another way to do this
without the layered pane (i’m using a layered pane for the time ruler numbers)?