Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36645

Re: How are you supposed to set JTable height?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: How are you supposed to set JTable height?
Date 2017-05-19 14:29 -0400
Organization A noiseless patient Spider
Message-ID <ofndc1$jde$1@dont-email.me> (permalink)
References <5749752d-bc83-4fb5-9abc-1a255e213a29@googlegroups.com> <ofn2ds$4uu$1@dont-email.me> <92a3c52c-8ac7-49f5-9b46-794224e13642@googlegroups.com>

Show all headers | View raw


On 5/19/2017 1:45 PM, Eric Douglas wrote:
> On Friday, May 19, 2017 at 11:22:59 AM UTC-4, Eric Sosman wrote:
>>       As for what to do about it, it depends on, well, on what you're
>> trying to do.  fireTableDataChanged is a "big hammer" (not as big as
>> fireTableStructureChanged, but plenty big) that smashes the old table
>> to fragments and builds a fresh one from the ruins (if you'll pardon
>> the violence of the imagery).  There are other events with more limited
>> and less drastic effects:
>>
>>       - fireTableRowsUpdated notifies the table that the contents of a
>> range of rows may have changed.  Listeners typically just repaint
>> those rows, leaving their decorations and whatnot intact.
>>
>>       - fireTableCellUpdated is an even more limited event, reporting
>> the possible update of one single cell (which gets repainted if it
>> happens to be visible).
>>
>>       - fireTableRowsDeleted and fireTableRowsInserted do what you'd
>> expect.  I believe they'll leave the appearance of the surviving or
>> relocated rows unchanged.  (Trust, but verify.)
>>
> 
> So I guess I've been doing it wrong.  The hammer approach may not hurt if you're not using anything it smashes, and I normally don't do things like set individual row heights, but I had coded all my methods from deleting a row to changing one cell color to call the TableDataChanged.  I don't recall now if there was a reason I did that, if more specific fire methods gave me a problem, or if it just seemed easier.  So if anything the smaller hammer would be better, to just call fireTableRowsUpdated(0,table.getRowCount()) if we know the number of rows isn't changing.  That should at least fix custom row heights. I'll try getting more specific and see what kind of trouble it brings.

     Sounds plausible (after correcting the off-by-one error).  If
you can identify the updating range more closely and wind up firing
a more specific TableModelEvent, you'll also avoid those unnecessary
repaints (and/or visibility determinations) of unchanged rows and
cells.

     Not so sure about that "changing one cell color" bit, though.
That's probably not a change the TableModel should be involved in;
rather, I'd suggest using a custom cell renderer (and, in extreme
circumstances, a custom JTable subclass) -- it can make a color
decision based on the cell's content, location, whatever, and make
that decision independently of other tables that could be browsing
the same TableModel for their data.  See

http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#renderer

-- 
esosman@comcast-dot-net.invalid
Thirteen hundred forty-two days to go.

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How are you supposed to set JTable height? Eric Douglas <e.d.programmer@gmail.com> - 2017-05-19 07:20 -0700
  Re: How are you supposed to set JTable height? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-05-19 11:22 -0400
    Re: How are you supposed to set JTable height? Eric Douglas <e.d.programmer@gmail.com> - 2017-05-19 10:45 -0700
      Re: How are you supposed to set JTable height? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-05-19 14:29 -0400
        Re: How are you supposed to set JTable height? Eric Douglas <e.d.programmer@gmail.com> - 2017-05-19 11:42 -0700
          Re: How are you supposed to set JTable height? Eric Douglas <e.d.programmer@gmail.com> - 2017-05-19 13:06 -0700
            Re: How are you supposed to set JTable height? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-05-20 07:59 -0400
              Re: How are you supposed to set JTable height? Eric Douglas <e.d.programmer@gmail.com> - 2017-05-22 04:55 -0700
                Re: How are you supposed to set JTable height? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-05-22 09:00 -0400
                Re: How are you supposed to set JTable height? Eric Douglas <e.d.programmer@gmail.com> - 2017-05-22 06:42 -0700
                Re: How are you supposed to set JTable height? Eric Douglas <e.d.programmer@gmail.com> - 2017-05-22 09:18 -0700
                Re: How are you supposed to set JTable height? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-05-22 17:15 -0400

csiph-web