2. I am trying to set the rows and columns of the text area. After I set them using setRows and setColumns of JTextArea methods, it shows in the console that they are set when I see them using getRows and getColumns but I could not actually see the text area widening up. It also affects the sizes of the labels...
Here is the Java code for the Interface.java file
Welcome to JavaRanch!
First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name; "handles" and joke names don't work at the Ranch. You can change your display name here. Thanks!
Now, as to your question: the preferred sizes of all components managed by a GridLayout are totally ignored. The size of the parent is divided into a grid of equal sized boxes, and the components are sized to fit the boxes. This is documented on GridLayout's Javadoc page.
We've got a forum devoted to Swing and AWT issues here. I will move this there for you.
[ December 20, 2005: Message edited by: Ernest Friedman-Hill ]
Originally posted by Ernest Friedman-Hill:
...the preferred sizes of all components managed by a GridLayout are totally ignored. The size of the parent is divided into a grid of equal sized boxes, and the components are sized to fit the boxes. This is documented on GridLayout's Javadoc page.
I wouldn't say that GridLayout total ignores the preferred sizes of the components. Consider this demo: all the components end up with size 200x200:
With frame.pack, containers *may* (depending on how they're nested etc..) ask their layout managers to compute a preferred size, and in turn that *may* cause the layout managers to ask the container's components about their preferred sizes. In the above example, the components say 100x200 or 200x100, and the GridLayout combines that to come up with a 400x400 container, divided into four 200x200 cells.
As for the original posting, the key thing to realize is that in a GridLayout, all rows will have the same height and all columns will have the same width, and that is why the button has so much space around it. You're going to have to use a different layout, like GridBagLayout, or nest layouts further, to get what you want.
2. I have another doubt...when I import java.awt.*, why do I have to import java.awt.event.* for using ActionListener...why don't the former import work?
Here is the new code...
[ December 20, 2005: Message edited by: Raghavan Chockalingam ]
2.That's the way imports are defined to work. As far as importing is concerned there's no notion of a "sub-package", so importing java.awt.* doesn't import any of the packages like java.awt.event. The spelling of the names is just coincidental.