• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about referencing a reused Swing component

 
john kalaigian
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I have a question regarding a JTextField that I created once and am reusing by calling the constructor over and over say:

And so on. Now I want to access the JTextField that has the name Two, and I want to be able to obtain the dimensions of this particular instance of field. How would I do this? I have the getName() method and I can do a comparison to see if it equals "Two" but aside from that what else can i do to actually get a hold of that reference to that object. Thanks in advance, John
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure about your question , but I'm guessing you can do something like:

Let me know if that's it...
 
john kalaigian
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried it - it didn't seem to work out. Gotta come up with an intricate way to do this - when i know there's an easy solution
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the best i can think of is to use the getComponents() method of the JPanel you puit all the textfields in.
then you get an array of the components. cycle through the array looking for the right name with getName() and when you find it then Voila!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!