Article View: borland.public.jbuilder.java.language
Article #17285Inconsistent list selection/highlighting
From: Ross M. Dukeshier
Date: Wed, 25 Nov 1998 00:00
Date: Wed, 25 Nov 1998 00:00
46 lines
2315 bytes
2315 bytes
A while back I developed a frame that searches the data in a JTable for
the first record that matches the value of a JTextField (up to the
number of characters typed in the text field). My JTable is in a
JScrollPane and it locates the record fine, even moves the Viewport of
the scrollpane to the right record. But it doesn't consistently
highlight the record. I've tried using the setLeadSelectionIndex and
setAnchorSelectionIndex methods (alone or together), and the
setSelectionInterval method. It seems like it almost alternates on
whether it's going to highlight it, but not quite. Setting the
selection interval twice has no effect.
I believe this is a paint/validate problem (if I scroll the row off the
viewport, then come back it is highlighted) but revalidating the table
doesn't do anything either.
I'm on a Windows NT/95 system, using JDK 1.1.6
and JDK 1.2 (same in both on both systems). Here's a sample of the code
that is supposed to do it...
private void setRow(int index) {
if (index > -1) {
crTableScrollPane.scrollRectToVisible(crTable.getCellRect(index,1,true));
if (crTable.getSelectedRow() == -1) {
crTable.getSelectionModel().setLeadSelectionIndex(index);
}
crTable.getSelectionModel().setLeadSelectionIndex(index);
}
else {
System.out.println("Resetting selection");
crTable.clearSelection();
}
}
The conditional setLeadSelectionIndex call made it work before I added
the scrollRectToVisible call (Don't ask me why).
Has anyone out there had a similar problem? I'd appreciate knowing I'm
not alone almost as much as I'd appreciate the solution to the
problem...
Any help would be appreciated.
Thanks in advance,
Ross Dukeshier
Technical Details
Message-ID:
<365BFABB.562@flash.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,47c16c4a3f73a536,start X-Google-Attributes: gidf74b3,public From: "Ross M. Dukeshier" <dukeman@flash.net> Subject: Inconsistent list selection/highlighting Date: 1998/11/25 Message-ID: <365BFABB.562@flash.net> X-Deja-AN: 415509508 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Reply-To: dukeman@pop.flash.net Newsgroups: borland.public.jbuilder.java.language