JScrollPane

Hi again evryone in the forum,does anyone know how can be a scroll, which has been moved down to observed all values of a table, been moved to the upper position of the table?Many thanks in advance.
[219 byte] By [patucosa] at [2007-10-3 3:48:04]
# 1
Didn't I give you this one earlier?scrollPane.getViewport().scrollRectToVisible(...);For the top just use a new Rectangle(0, 0, 0, 0)...
itchyscratchya at 2007-7-14 21:45:04 > top of Java-index,Desktop,Core GUI APIs...
# 2
upps sorry it is true, i did not realize of it (i wait till the last minute to do this part of the program and now under stress is not a good way of working) Many thanks for the help
patucosa at 2007-7-14 21:45:04 > top of Java-index,Desktop,Core GUI APIs...
# 3

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);

patucosa at 2007-7-14 21:45:04 > top of Java-index,Desktop,Core GUI APIs...
# 4
Are you calling it on the event dispatch thread?
itchyscratchya at 2007-7-14 21:45:04 > top of Java-index,Desktop,Core GUI APIs...
# 5
I usetable.scrollRectToVisible(...)and it works fine.
camickra at 2007-7-14 21:45:04 > top of Java-index,Desktop,Core GUI APIs...
# 6

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;

}

}

patucosa at 2007-7-14 21:45:04 > top of Java-index,Desktop,Core GUI APIs...
# 7
Thanks a lot for the help both of you guys, the scroll is working :)
patucosa at 2007-7-14 21:45:04 > top of Java-index,Desktop,Core GUI APIs...