How to get the object who called DocumentFilter

47 views Asked by At

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.

1

There are 1 answers

0
StanislavL On

DocumentFilter has reference to a Document 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 access JTextField.

You can extend the DocumentFilter and add a source JTextField directly. Just create as many as you need DocumentFilter for each your text field.