johnchan2000
asked on
Scrolls to Always Show Selected Row in JTable on Top of scrollpane
Experts,
I am writing a simple lookup window. It has a table with two columns(column 1 is abbreviations, and column 2 is the description). The window provides this incremental search kind of capability(as you type in the search JTextField, it highlights and scroll to the closest match on the table). The problem I have is this: I managed to get it to highlight and scroll to show the match item on the table BUT what I would like to be able to do is to ALWAYS have the highlighted/matched item to be on top of the table.
Example: Table has 5 rows (a,b,c,d,e) but only two rows are visible(a &b)
When I typed in d, it scrolls down two rows and shows c and d
What I really want is for it to scroll far enough to ensure that d would be the topmost visible row on the table(show d and e instead of c and d).
I want this same effect regardless it's scrolling up or down.
Here's the code snippet that does the highlighting and scrolling (but highlighted item does not go to top of table)
if(str.startsWith(searchPa ttern))
{
lookupTable.setRowSelectio nInterval( i,i);
Rectangle rect = lookupTable.getCellRect(i, 0,true);
lookupTable.scrollRectToVi sible(rect );
break;
}
Any help is greatly appreciated,
John
I am writing a simple lookup window. It has a table with two columns(column 1 is abbreviations, and column 2 is the description). The window provides this incremental search kind of capability(as you type in the search JTextField, it highlights and scroll to the closest match on the table). The problem I have is this: I managed to get it to highlight and scroll to show the match item on the table BUT what I would like to be able to do is to ALWAYS have the highlighted/matched item to be on top of the table.
Example: Table has 5 rows (a,b,c,d,e) but only two rows are visible(a &b)
When I typed in d, it scrolls down two rows and shows c and d
What I really want is for it to scroll far enough to ensure that d would be the topmost visible row on the table(show d and e instead of c and d).
I want this same effect regardless it's scrolling up or down.
Here's the code snippet that does the highlighting and scrolling (but highlighted item does not go to top of table)
if(str.startsWith(searchPa
{
lookupTable.setRowSelectio
Rectangle rect = lookupTable.getCellRect(i,
lookupTable.scrollRectToVi
break;
}
Any help is greatly appreciated,
John
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes thats what I suggested, thanks for saving me the time to type it out :)
We're here to help as good as possible. Not to provide answers like riddles.
That's why I posted some relevant code that really shows how.
The author of this question will decide.
That's why I posted some relevant code that really shows how.
The author of this question will decide.
> The author of this question will decide.
I explained how to do, and you wrote an example implementing my suggestion.
whats there to decide ???
I explained how to do, and you wrote an example implementing my suggestion.
whats there to decide ???
> Not to provide answers like riddles.
And theres no riddle (even you understood). John knows that all he needs to do is ask if he requires more details on the implementation and I am more than happy to provide clarification.
And theres no riddle (even you understood). John knows that all he needs to do is ask if he requires more details on the implementation and I am more than happy to provide clarification.
>> Not to provide answers like riddles.
...and certainly not to fill up a thread with quarreling like you do now
>> I am more than happy to provide clarification
Then why aren't you if others do?
Or should I've asked you first if I was allowed to?
...and certainly not to fill up a thread with quarreling like you do now
>> I am more than happy to provide clarification
Then why aren't you if others do?
Or should I've asked you first if I was allowed to?
I'm not quarrelling :-D All I did was thank you, sorry if you took that as argumentative (though i'm not sure how).
ASKER
Worked exactly as I wanted it.
Much Appreciation.
Regards,
John
Much Appreciation.
Regards,
John
Glad we could help :)
>> Worked exactly as I wanted it.
Nice!
Thanks for accepting.
Nice!
Thanks for accepting.
Thanks John :-)