Hello all. I am new to this discussion forum and would greatly appreciate anyone's help on this one. This is a great site!! Thank you all for being here.
Here's my problem:
I'm working on an application that has a JPanel that is a grid layout with three columns of jtextfields (among other things). I have created a custom focus traversal policy to be able to transfer focus between these textfields as applicable. When I test my code in the getComponentAfter method, returning any specific element in any of the arrays it works fine..focus is transferred like it should.
example:
[ return bstextfields[3] ]
but since i have a variable number of elements in these arrays, determined by the user at the beginning of the application, the getComponentAfter method looks through the arrays for a match to decide what textfield element to return and then must return the textfield element with a variable subscript like this:
[ return bstextfields ]
The program freezes when i do this. Focus is not transferred to any of these textfields...in fact it is lost entirely (no blinking cursor in any of the textfields).
If there were a way to use macro substitution...or something like that, I think that would fix it. For example, if i was 7, I would grin from ear to ear if I could substitute that 7 and return a literal value, like the compiler apparently needs..like this:
[ return bstextfields[7] ]
Sorry so long winded. Anyway, here's the chunk of code:
public Component getComponentAfter(Container focusCycleRoot, Component aComponent)
{
int i;
for (i=0; i<=SETUPS; i++)
{
if (aComponent == bsTextFields[i]) // aComponent is losing the focus
{
i = SETUPS;
return fsTextFields[i];
}
if (aComponent == fsTextFields[i])
{
i = SETUPS;
return descripTextFields[i+1];
}
if (aComponent == descripTextFields[i])
{
i = SETUPS;
return bsTextFields[i];
}
}
// if problem, fall through to this to make compiler smile :)
System.out.println("bsTextFields[5] returned");
return bsTextFields[5]; // MAKE COMPILER HAPPY !!
} // end getComponentAfter
Thank you all so much.