ArrayList<JtextField> texts = new ArrayList<JTextField>();
texts.add(A1Box); //A1Box is a previously declared JTextBox
It says it cant find A1Box, even though i know it has been declared / initialized already.
so is there some other way I can search through all the boxes on the page? I need to do a lot of code to each box, so just searching through them all manually with a case statement would definitly not work if i need to change something.
That suggests that A1Box was declared in a different scope than the one you are trying to use to store it in the ArrayList.
What exactly are you trying to do? Why do you need to look up the text boxes?
Jake Wilson wrote:Yeah, I thought the scope thing as well, but im pretty sure that its all in the same scope. I need to search through all the textboxes, get the name out of them and do a couple things to them. Nothing that requires a ton of code. So was the way that I did it the right way?
Well, it depends on the error -- is this a compile time error? or a runtime error? At compile time, if it can't find the reference, it is generally because you are using it out of scope... can you show us some code? .... And what do you mean by "pretty sure" -- either it is, or it isn't.
At runtime, how are you searching for it? The JTextField doesn't override the equals method, so the only way to find the JTextField in question, is if you already have a reference to it. It doesn't make sense to "search" for it.
Campbell Ritchie wrote:Welcome to JavaRanch
You could put your JTextFields into an array with two sets of square brackets (JTextField). That might make it easier to handle when you set up your layout. And you can iterate through the array with [two nested] for loops or for-each loops.
Except i cant put them in anything, for some reason the scope is off. I dont have to do anything special to put the textboxes into the array do it?
arraylist.add(textbox) should work right?
You can then retrieve the individual boxes from the array or from the List.
And I think I said JTextBox when I meant JTextField, but I am sure you know what I mean