public void pack()
Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.
If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size.
The Window will be validated after the preferredSize is calculated.
SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...
That should keep you busy all day.Those are my questions so far.
SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...
Originally posted by Joane Denise Saulon:
1. Since it is better to use LayoutManagers than manually laying out the GUI yourself, we therefore have to abide by the LayoutManager's policies.
But still I find some limitations to the LayoutManagers. For example, how am I gonna display this (I'm sorry, please just imagine that "Big Area 1" and "Bigger Area 2" are boxes representing the parts of the GUI):
~~ Big Area 1 ~~ ~~ Bigger Area 2 ~~
~~ Big Area 1 ~~ ~~ Bigger Area 2 ~~
Button1 Button2 ~~ Bigger Area 2 ~~
Button3 Button4 ~~ Bigger Area 2 ~~
Based from my understanding, FlowLayout is from left to right ("wrapped"). BoxLayout is from top to bottom.
I'm thinking if making 3 panels would make it possible: Panel 1 for Big Area 1; Panel 2 for Bigger Area 2; and Panel 3 for the 4 buttons below Big Area 1. However I still can't figure out how to put these 3 panels together (please refer to question b).
a. Is it possible to add multiple panels in one JFrame?
b. If it is, how can we put it in such a way that it will just be the whole area of the JFrame? I mean, without setting the layout manually and without putting something else in the NORTH, EAST, SOUTH, WEST sides of the JFrame's BorderLayout? Just all the 3 panels in the CENTER Area (and no spaces in the N, E, S, W areas).
2. I think I missed something about the pack() method. What is it all about? The screen looks different if there is a pack method and if there is none. And I assumed that it is always required when displaying a Frame because if I delete that .pack() part, I could not see the whole frame at all.
[/QB]3. I get an exception when I use JFrame.add(). And the message says that I should use the getContentPane().add() instead.
a. Why should I use JFrame.getContentPane.add() instead of JFrame.add()?
b. What Content Pane will be retrieved on the getContentPane? Is there a "default" ContentPane for every JFrame that is retrieved upon invoking the getContentPane()?
c. What is it's difference then with the getRootPane()? Why not just use JFrame.getRootPane.add() instead to get the "default" ContentPane.[/QB]
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Originally posted by Campbell Ritchie:
[QB]
If you get an Exception when using the add() method, please check:Which version of Java you are using. There were additional add() methods added in Java5, so they won't work on Java1.4.2. Whether the arguments you are passing match the add() method; if you go through the API for Component and JComponent you will find add() has been heavily overloaded. As far as I know, the add() method was overloaded in Java5 so if you say add() rather than getContentPane().add() it defaults to adding to the content pane. There are more details about how a Frame works in the Java Tutorials: look for "top level containers" and "how to make frames." But don't add anything to the root pane.
[QB]
SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...
SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...