Is the following statement true or false? If you specify the anchor field in the GridBagLayout, there is no meaning to set fill field to BOTH. By the way, in GridBagLayout, what is the difference between anchor field, fill field and pad field? Thanks!
I give you a good link for this. Please read this and play with the sample code given. You WILL definitely be able to answer your qstn. Because this is the ONLY BEST WAY you can takle GBLayout qstns. Just giving answer WILL NOT help atleast for this case. Please come back after testing info in this link. We will definitly be here for you. regds maha anna Good tutorial for GridBagLayout is here
Hi, anna, I read the tutorial that you recommended. It's helpful. So, according to my understanding, the following statament should be correct. "If you specify the anchor field in the GridBagLayout, there is no meaning to set fill field to BOTH." Am I right?
Wai Iu, It is the other way around. When you set the fill field of GBC to BOTH, then the anchor field has no effect The idea here is both fields anchor and fill comes into picture when a component in a row/col gets extra space than the the size of the component itself. So when a comp gets lots od space, where to anchor the component? In Java AWT if you take any component, it is of shape Rectangle. Isn't? So GBC has totally 8 compass directions to anchor the comp. Go from NORTH to clockwise. NORTH/NORTHEAST/EAST/SOUTHEAST/SOUTH/SOUTHWEST/WEST/NORTHWEST. So the tiny comp. can be set to one of the above 8 directions. The anchor field has done its part. The fill field is used to In which direction (Horizantal/vertical/None/Both) to stretch. When you set this field to BOTH, the LayoutManager stretches the comp to ALL available space right? Then where is the qstn of where to anchor the comp? It is spread all over its allocated space already. Also note that GridBagLayout gives the combined effect of all its fields (fill/anchor/ipadx/ipady/gridx/gridy/gridwidth/gridheight/weightx/weighty/insets...Are they enough )when placing a comp. regds maha anna [This message has been edited by maha anna (edited April 09, 2000).]
You can't have everything. Where would you put it?