• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is the unit of parameters????

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic