Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Component number inside GridLayout.  RSS feed

 
Heinrich Umdelin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I have a 6x6 GridLayout with JButtons inside a JFrame. Now there is a method getComponent(int i) wich will give you the i'th Component counting from top left corner down. I seem to remember (maybe wrongly) that there is a method which will return
this component number for Component. But searching the docs for eg AbstractButton comes up with nothing. Pointers ?
 
Campbell Ritchie
Sheriff
Posts: 53749
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

I went to the API index -> G -> ctrl-F -> "getComponent" but I couldn't find a method called "getComponentNumber". Nor could I find such a method in Container or Component.

It seems non-object-oriented that a child Component know which order it was added to a parent Component/Container. It would be the parent Component/Container which ought to know that.
There are methods like getComponents() which return all the child Components (presumably as Component[]); they might help.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition to what Campbell said, you can also use getComponentCount() and getComponentAt(int index).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!