I am writing an application that is a virtual notebook. The idea is to have panels with various content (which is based on an external file) added to a panel that acts as a page. Once that page is full, its specialized add method should return false.
The problem is that I can't figure out how to accurately determine the size of the panels when I'm adding them, so I end up adding too many. The preferredSize of the panels is generally too short, and the size has 0 height. Is there a way to determine the exact size that a component is taking up in a layout?
I've tried using doLayout(), but it doesn't seem to change the size or preferredSize of my components. Maybe I'm not using it right? Here is the add method: (The contentPanel has BoxLayout, and the content panel doesn't have a set size, but is added to a panel (this) that does. The class this method is in extends JPanel)
public boolean addSpecializedgPanel(SpecializedPanel sp) {
this.contentPanel.add(sp);
this.doLayout();
if (this.contentPanel.getSize().height > this.getHeight()) {
this.contentPanel.remove(sp);
return false;
}
return true;
}
Thanks for any help (even if it criticizes my whole design :) )! This has been a huge headache!