Author | Topic: Gridlayout |
Thanuja greenhorn |
posted May 17, 2000 10:45 AM
Hi, I have a qstn regarding gridlayout. Let's see an ex. If you have a gridlayout like Gridlayout(3,1) i.e 3 rows and 1 col and if you try to put 4 buttons. then it should first fill the three rows and then put the fourth button in the first row second col right. But it is distributing the buttons in two rows two col's why?? I thought it will show up like but1 but2
but1 but2 Please explain.
|
Ajith Kallambella ranch hand |
posted May 17, 2000 10:49 AM
Hi Thanuja, The order of insertion is left to right, top to bottom. Ajith
|
Suryakumar unregistered |
posted May 17, 2000 10:53 AM
Hi Thanjua, I guess we don't have any control over GridLayout. According to the frame size it will be arranged. Am I correct. Pls. correct me. Thanks
|
Suma Narayan ranch hand |
posted May 17, 2000 11:13 AM
Hi Thanuja, In GridLayout: 1. Components appear in the order in which they are added, from 2. If number of components > fixed rows and columns, then number of culumns will be increased. Considering the above points, you get the result as but1 but2 Few more interesting points. 3. If you specify number of rows as zero, the layout manager 4. Similarly, if you specify number of columns as zero, 5. Remember, you CANNOT specify both rows and columns as zero, which is quite obviuos. I hope this helps you. Suma [This message has been edited by Suma Narayan (edited May 17, 2000).]
|
maha anna bartender |
posted May 17, 2000 11:16 AM
Suryakumar, yes. GridLayout is the meanest one from the component's preferred size point of view. In the sense it bothers neither preferred width/preferred height of the container's components. At the same time we can say it is a PERFECT MODERATOR by equally dividing the whole available container area and treating all the components SAME. Also note that according to the frame size has to be sightly changed. If the Frame's layout is set to GridLayout type then the Frame's size is equally divided. If it is set to a Panel then the Panel's whole area is equally divided. So we should say GridLayout arranges all the components (gives each comp same size) accoding to the container's size the GridLayout is set as LayoutManager. Frame is also a container. regds [This message has been edited by maha anna (edited May 17, 2000).]
|
Ajith Kallambella ranch hand |
posted May 17, 2000 11:18 AM
Surya, You are right, GridLayout will not honor the preferred size of your component. But the question here is not about the size, but about the order of placement of components. It is row major placement ie., it fills up the row before moving on to the next one. Hope this clarifies. Ajith
|
Ajith Kallambella ranch hand |
posted May 17, 2000 11:22 AM
Suma, Just one addition to your scenarios. You can create a GridLayout with no args. In such a case, it keeps the row fixed to one, and keeps on adding new columns to it every time you add a component. I have seen such a question in one of the mock exam, I don't remember which one, where they constructed a GridLayout with no arguments and added a few components. One might get misled thinking that would cause a compiler error!!
|
Suryakumar unregistered |
posted May 17, 2000 11:27 AM
Thank you Ajith and Maha. Now I got it. Surya
|
Suma Narayan ranch hand |
posted May 17, 2000 11:33 AM
Ajith,
Suma
|
Jim Yingst sheriff |
posted May 17, 2000 01:06 PM
One more point to add to Suma's first post- if you specify both the number of rows and columns as non-zero, then the number of columns you specify is ignored, and instead determined only from the number of components actually added to the layout manager. As Suma said, this is also what happens when you specify that the number of columns is zero. So, the only way you can really specify the number of columns is to make the number of rows zero, and the number of columns non-zero. Then it uses the number of columns you specify, and adjusts the number of rows to fit the number of components. Frankly, it's a rather poorly designed class IMO. The constructors are misleading - at least one of the parameters (rows or columns) is meaningless, however you call it. And the setColumns() method has no effect unless rows are set to zero. This is mentioned if you read the documentation, but it seems rather counterintuitive.
|
| | |