Im making a sudoku game, I have 9x9 objects of type "cell" (class extends JTextField), i want to to prevent focusing on other JTextField objects if the user doesn't meet the game rules - his input(1-9) wont be at the same row or the same "block". To do this i need to know the specific object he is focused on.
One way i was thinking of doing that is by using DocumentFilter. I already filtered the input to digits and to 1 length, but i have no clue how to get that "cell" object he is focused on, Im pretty sure the DocumentFilter methods get that object somehow but i couldn't find how, any help? Thank you.
DocumentFilter
has reference to aDocument
but Documnets are just models. The same document instance can be set to more than one text component. Thus you won't be able to accessJTextField
.You can extend the
DocumentFilter
and add a sourceJTextField
directly. Just create as many as you needDocumentFilter
for each your text field.