Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hiding rows on a JTable object???

756 views
Skip to first unread message

john doe

unread,
Apr 6, 1999, 3:00:00 AM4/6/99
to
I'm wondering if someone has already done or seen this somewhere:

I'm looking for a class that would extend the JTable class, so that this new
class allows hiding of rows. What I mean is that sometimes I would some
rows not to be displayed, but I don't want to have to delete all the data in
the table, and then refilling it.

Thanks in advance

Johannes Hubert

unread,
Apr 7, 1999, 3:00:00 AM4/7/99
to
Here's a hint:

Override an own version of a TableModel which keeps a flag associated with
each row (visible/invisible) and only "shows" rows that have the flag set.
This has the effect that your model still contains all the data, but that it
simply doesn't show all of it to the view.

Johannes.

john doe wrote in message <7edm9c$14s$1...@bcarh8ab.ca.nortel.com>...

john doe

unread,
Apr 7, 1999, 3:00:00 AM4/7/99
to
Thanks for your response!

How exactly does the TableModel/JTable display the rows though? I haven't
seen anything in the documentation that shows how it is done. Since, I'd
only want to show the rows that have the flag set, I would have to modify
something somewhere to tell the TableModel/JTable to display these
"selected" rows only, but I really don't know where to look...

Thanks again


Johannes Hubert wrote in message <7ef0da$l0i$1...@minox.tripnet.se>...

mark

unread,
Apr 7, 1999, 3:00:00 AM4/7/99
to
i'm guessing that a combination of getColumnCount() and getColumnName() would
handle it. getColumnCount()'s return value could depend on the number of
columns with the flag set to visible, and getColumnName() would provide the
column name. I'm planning to implement this feature in the next couple weeks,
so i haven't really looked at it yet. i'm just a beginner, so i'd be interested
in any particular elegant ideas.
-mark weaver

john doe wrote:

--
mark weaver
http://www.geocities.com/~velosapiens
a source of important and interesting information for mountain bikers

john doe

unread,
Apr 7, 1999, 3:00:00 AM4/7/99
to
I'm really interested in rows, not columns!

Thanks anyways.


mark wrote in message <370B80F4...@abtcorp.com>...

Frans van Duinen

unread,
Apr 8, 1999, 3:00:00 AM4/8/99
to john doe
When you use a TableModel (extend AbstractTableModel), you provide a
number of routines (e.g. gatRowCount() and getValueAt( row, col)) that
are called by JTavle to build and populate the table that it displays.

If you want to hide certain rows or columns, the first thing to do is to
make those routines smart enough to skip those rows and columns the next
time JTable calls them.

E.g. if you have 121 rows of data and you want to hide row 41,
getRowCount will have to tell JTable there are 120 rows. Similarly when
getValueAt gets called for any row after row 40, it should return the
row after in the underlying data (array, resultset etc).

The second thing you have to do is tell JTable about the rows that are
deleted (from the view) or added to it. There are a whole series of
fireTablexxxyyy() methods, such as fireTableRowsDeleted( r1, r2) to
delete a range of rows.

Sun has a very good tutorial on this. Look for the BINGO application.

=============
----------------

--
Frans van Duinen (416) 652-8085
Master Programmer Group Inc.
Toronto, Ont.

0 new messages