Article View: borland.public.jbuilder.java.swing
Article #7990Re: row visible in a jtable
From: Christian Kaufhold
Date: Sat, 04 Nov 2000 00:00
Date: Sat, 04 Nov 2000 00:00
60 lines
2473 bytes
2473 bytes
"San LUC \(webmail.alten.fr\)" <sluc@webmail.alten.fr> wrote:
> Does anyone how I can test if a row is visible in a jtable and scroll to it
> ?
UNTESTED:
Rectangle visible = table.getVisibleRect();
Rectangle r = table.getCellRect(row, 0, true);
if (visible.contains(r))
System.err.println("Completely visible");
else if (visible.intersects(r))
System.err.println("Partly visible");
else
System.err.println("Not visible");
Scrolling can be done with the standard method scrollRectToVisible.
public static void makeRowVisible(JTable table, int row)
{
/* These two lines are new since the last time I posted this. */
if (table.getColumnCount() == 0)
return;
if (row < 0 || row >= table.getRowCount())
throw new IllegalArgumentException(String.valueOf(row));
Rectangle visible = table.getVisibleRect();
Rectangle cell = table.getCellRect(row, 0, true);
if (cell.y < visible.y)
{
visible.y = cell.y;
table.scrollRectToVisible(visible);
}
else if (cell.y + cell.height > visible.y + visible.height)
{
visible.y = cell.y + cell.height - visible.height;
table.scrollRectToVisible(visible);
}
}
Followup-to set.
Christian
--
"But glory doesn't mean 'a nice knock-down argument,'" Alice objected.
"When I use a word," Humpty Dumpty said, in a rather scornful tone, "it
means just what I choose it to mean -- neither more nor less."
Through the Looking-glass
Technical Details
Message-ID:
<8u143b$bdi$01$1@news.t-online.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8tur22$poi$1@reader1.fr.uu.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,8fd41f5c9ef3d9da
X-Google-Attributes: gid111d45,public
X-Google-Thread: 10fd6d,8fd41f5c9ef3d9da
X-Google-Attributes: gid10fd6d,public
From: ch-kaufhold@gmx.de (Christian Kaufhold)
Subject: Re: row visible in a jtable
Date: 2000/11/04
Message-ID: <8u143b$bdi$01$1@news.t-online.com>
X-Deja-AN: 689591514
Content-Transfer-Encoding: 8bit
References: <8tur22$poi$1@reader1.fr.uu.net>
X-Sender: 320012127596-0001@t-dialin.net
Followup-To: comp.lang.java.gui
Content-Type: text/plain; charset=ISO-8859-1
X-Complaints-To: abuse@t-online.com
X-Trace: news.t-online.com 973345708 01 11698 gisOy2TSWYkuz 001104 13:48:28
Organization: Uni Bremen, ZfN
User-Agent: tin/1.4.4-20000803 ("Vet for the Insane") (UNIX) (Linux/2.2.17 (i586))
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing,comp.lang.java.gui