Just one thing.
i have tryed with the rect 0,0,0,0 or with the first value of the table but the scroll does not move. Any explanation?
Thanks in advanced
table.getSelectionModel().setSelectionInterval(0, 0);
Rectangle r = table.getCellRect(table.getSelectedRow(), 0, false);
scrollPanel.getViewport().scrollRectToVisible(r);
Rectangle r = new Rectangle(0, 0, 0, 0);
scrollPanel.getViewport().scrollRectToVisible(r);
Yes i am calling the function in a event of a button, i mean, when it is clicked.
ImageIcon icon = new ImageIcon("icons/watch.gif");
JButton buttonSearch = new JButton("Search",icon);
buttonSearch.addActionListener(
new ActionListener(){
public void actionPerformed (ActionEvent evt) {searchString(textField.getText().trim());
textField.setText("");
}
}
);
buttonSearch.setToolTipText("Click this button to search"
+ " for a command or a molecule.");
c.gridx = 1;c.gridy = 0;
aux.add(buttonSearch, c);
........................................
private static void searchString(String text){
table.getSelectionModel().setSelectionInterval(0, 0);
Rectangle r = table.getCellRect(table.getSelectedRow(), 0, false);
scrollPane.getViewport().scrollRectToVisible(r);
if (tabbedPane.getSelectedIndex() == 1){
for (int i= 0; i < table.getRowCount(); i++) {
if ((table.getValueAt(i,0).toString().toLowerCase()).contains(text.toLowerCase()))
{
table.getSelectionModel().setSelectionInterval(i, i);
r = table.getCellRect(table.getSelectedRow(), 0, false);
scrollPane.getViewport().scrollRectToVisible(r);
return;
}
}