• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Use getGridx()

 
Ted Newholm
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone show me how to use getGridx() and getGridy() in relation to the GridBagLayout.

I've looked at several sites but haven't been able to find a definitive example showing this.

I'd like to get the gridx and gridy components of a GridBagLayout cell, one that contains a specific component.


Thanks,
 
Korhan Rankin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ted,

gridx and gridy values are defined with GridBagConstraints for a component in GridBagLayout. I've never tried to get the GridBagConstraints back once I set them when adding a component to another.

Without using google.. what you can try is to set specific gbc constraints gridx or y values, for example 1337, add a component to another one using that prepared gbc, go into debug mode and try to find them in the components. When found look for a way to get them, last but not least using reflection api.

hope it is of any help

cheers.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I shall move this thread to our GUIs forum.
As you have been told, those values are fields (public fields ) of the GridBagConstraints class
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone show me how to use getGridx() and getGridy() in relation to the GridBagLayout.


There are no such methods. You need to create your own.

The GridBagLayout does have a



method. So if you know the component you can find out the the gridx/gridy values. Or if you want to find the component for a given gridx/gridy then you will need to loop through all the components on the panel and find the components with the specified constraints. The Container class has a method that allows you to get all the components. You can then loop through the array.
 
Ted Newholm
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info. I could find references to getGridx when I Googled it but it never showed it like a regular method. Now I know why.
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!