I have a JPanel that uses a FlowLayout and contains many JButtons. The buttons are in a 2-dimensional grid (by the FlowLayout). The JPanel can be resized, and, of course, when it is, the location of the buttons in the grid changes (although the order, of course, stays the same). I want the user to be able to navigate from one button to another in the grid by using the arrow keys on the keyboard.
Is there a way to tell for a given button, which button is currently directly above it, which button is directly below it, and which buttons are to its immediate left and right?
Obviously, this would be trivial if I were using a GridLayout, but I need to use a FlowLayout for other reasons.