My Code:
public MyConstructor() {
view = new JPanel(new GridLayout(3, 1));
header = new JPanel(new GridLayout(2, 1));//2 ROWS 1 COLUMN
foot = new JLabel("Copyright...");
content = new JPanel();
info = new JLabel("");
logo = new JLabel() {
BufferedImage img;
@Override
public void paint(Graphics g) {
try {
img = ImageIO.read(new File("logo.jpg"));
} catch (IOException e) {
}
g.drawImage(img, 0, 0, null);
}
};
window.add(view);
header.add(logo);
header.add(info);
view.add(header);
view.add(content);
view.add(foot);
window.setLocation(width / 2, 100);
window.setSize(width, height);
window.setPreferredSize(new Dimension(width, height));
content.setSize(window.getWidth(), height-70);
content.setPreferredSize(new Dimension(window.getWidth(), height-70));
}
"window" is the frame...the class is not extending JFrame My class is going to be a super class to others, the subclasses inherit the public content JPanel. In my super class i'm trying to set the width and height of the 3 sections of my GridLayout, the logo and info components add up to 70 for their height...I've set the other components (view,header,info,logo) private so that subclasses can't access them...
When the application runs a window is shown for the login, this displays and resizes properly. once logged in an instance of one of the subclasses is created, the login window is then hidden site setVisible(false)
when the new window is shown however, the JFrame is the correct size but the header,content and footer are not the currect sizes. I've tried setting the size and preferred size each of the components but still not working...I've also tried calling repaint and validate/revalidate
Any ideas?