This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes What is the unit of parameters???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "What is the unit of parameters????" Watch "What is the unit of parameters????" New topic
Author

What is the unit of parameters????

Loveen Jain
Ranch Hand

Joined: Jan 24, 2004
Posts: 35
I have checked at a lot of places but i am not able to find that what is the measurement unit of the parameters which we pass during specifying the gridx, gridy, width, height, of the constraints in the GridBagLayout.
the api says that the parameter shud be of int type, but my problem is that wat does these parameters means.
eg
gridx[]={1,1,2};
gridy[]={1,1,1};
okay!!! now if we consider the above example than wat is this 1,1,1 is it centimeters, inches, pixels or wat???
please help me out with this, because of this confusion i am unable to put the controls correctly on the GUI applications.
Loveen
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

i don't think they are any specific anything. My understanding is that since different OSes will draw the same components differently, it doesn't make a lot of sense to say "DRAW IT HERE!!!"
this are (again, it's been a while) basically guidelines on how/where to draw them, but it will be slightly different from system to system, resolution to resolution, window size to window size.
and, this is really a good thing.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
If I understand what you are asking, the API doc says that GridBagConstraints.gridx specifies the cell containing the leading edge of the component's display area and GridBagConstraints.gridy specifies the cell at the top of the component's display area. I take this to mean that these are the column and row number of the cell in the top right corner of the component being placed with this layout. So the units would for gridx is the number of rows from the right (with the first row indicated by grid=0). Similarly gridy is the number of rows from the top.
Does this answer your question?


Java API Documentation
The Java Tutorial
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Looking at the java.awt.GridBagConstraints JavaDoc, if you go to the bottom of the page you'll see a description of the constructor, which lists all of the parameters.
The first four--about which you seem to be asking--are not specified in specific unit, but rather in "grids", or "cells". In other words, passing in "0,0,1,1" as the first four parameters simply means that you want the component to occupy the upper-left-most cell (0,0), be one cell wide and one cell in height. The actual height of the cell is determined by what component goes in there.
The other parameters let you specify padding, insets, whether the component should stretch or shrink with the window, etc.
GridBagLayouts take some time to "master", and are complicated, but allow you the best way of controlling the final layout. Check out Sun's GridBagLayout tutorial for additional information. If you 'google' on GridBagLayout tutorial you'll find other help.
Loveen Jain
Ranch Hand

Joined: Jan 24, 2004
Posts: 35
thankyou very much for replying to my querry,
but my question is still unanswered and i am still confused,
if I make out a conclusion from the answers of all three of you than also the problem persists that how is this grid or cells size decided because if i place a text area of lets say (40,150) in (0,0) position (can be a grid 0,0 or the cell okay!!!), and after that i try to place a radio button(checkbox) at the (0,1), than also i have to specify the width of the component, which is an integer parameter, isnt it. Now if i specify nothing for the first one because its too obvious that it will take the width of 150 characters as the number of columns is 150 in the size of text area. And now if i specify the gridwidth for the next radio button, and specify width 20, than wat will be this 20(pixels, cms, points or waht.....???)
please help me out because i am unable to place things because of this...

Loveen
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
The best thing to start with is to go to some of the AWT/Swing tutorials and play around with the layout managers until you get a better idea of what is going on. This is particularly true with the GridBagLayout. If you have access to an IDE that has a GUI layout tool (such as JBuilder), you can easily throw together a sample UI and start changing the parameters to see what happens.
Each component (java.awt.Component) has several methods that relate to size:
setSize(...);
setMaximunSize(...);
setMininumSize(...);
setPreferredSize(...);
Each LayoutManager uses some subset of those values and overrides other values when placing and sizing components. So the placement and size of a component is a combination of how the component is defined and what layout manager is used.
Generally the "GridBagLayout" will size a cell's height on the highest component in that row and the widest component in that column. Each cell defines what component is there [and you can stick multiple components in a cell, but that's bad technique], the insets, margins, offets, anchor location and x/y-scaling factor. And components can span multiple cells in either the X- or Y-direction, or both.
On a simple level, the GridBagLayout will query each of the components in a column how big they want to be (getPreferredSize()), then adjusts the answer based on insets, margins, offets, etc. It then takes the largest width and that's how wide that column will be. Each row can be a different height, and each column can be a different width. But notice that you are NOT specifying the height and width when you set up the GridBagConstraints or GridBagLayout. That comes from the components themselves.
So in your last example, the text area will probably be wider than the radio button, so the width of the first column will be enough to accomodate the text area, and the radio button will have lots of extra room.
Again, look for some tutorials and play around with each of the Layout Managers, but particularly on the GridBagLayout if that's what you want to learn and use.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: What is the unit of parameters????
 
Similar Threads
Using GridBagLayout
gridBagLayout
GridBagLayout ?
general question
problem in layout a form.