I have a GUI, which presents a table with thousands of rows and a few columns. I’m trying to iterate by row through some matches found in the GUI when the client uses my search functionality. I’m able to select the row to highlight a match just fine, but I don’t know what method to use to shift the focus of the GUI window to move over the next find.
In the following code, my_model is instantiated as a simple class which extends AbstractTableModel, and my_table is a standard JTable. Whenever a match is found, I want to be able to set the selected interval as the next find, and I also want to shift the window focus to have the next find in the middle.
int i, ln;
for ( i = 0, ln = my_model.getRowCount(); i < ln; i++ )
{
String cur_entry = (String)my_model.getValueAt(i, 1);
if ( ! cur_entry.contains(search_query) ) continue;
my_table.setRowSelectionInterval(i, i);
// This is where I'd like to focus the GUI window on row i.
String options[] = new String[]{"Find Next","Done"};
String initialValue = options[0];
int code = JOptionPane.showOptionDialog(null, "Continue Searching", "Find", 0, JOptionPane.QUESTION_MESSAGE, null, options, initialValue);
if ( code != 0 )
return;
}
Let me know if any further info is needed. Any help would be greatly appreciated.
Use this: