Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38847 > unrolled thread
| Started by | Andreas Leitgeb <avl@logic.at> |
|---|---|
| First post | 2019-04-03 15:53 +0000 |
| Last post | 2019-04-03 10:34 -0700 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
DefaultTableModel.getDataVector() and Java 11 Andreas Leitgeb <avl@logic.at> - 2019-04-03 15:53 +0000
Re: DefaultTableModel.getDataVector() and Java 11 Patrick Roemer <sangamon@netcologne.de> - 2019-04-03 18:37 +0200
Re: DefaultTableModel.getDataVector() and Java 11 Andreas Leitgeb <avl@logic.at> - 2019-04-03 16:41 +0000
Re: DefaultTableModel.getDataVector() and Java 11 Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-04-03 12:44 -0400
Re: DefaultTableModel.getDataVector() and Java 11 Andreas Leitgeb <avl@logic.at> - 2019-04-03 17:33 +0000
Re: DefaultTableModel.getDataVector() and Java 11 Eric Douglas <e.d.programmer@gmail.com> - 2019-04-03 11:22 -0700
Re: DefaultTableModel.getDataVector() and Java 11 Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-04-03 18:49 +0200
Re: DefaultTableModel.getDataVector() and Java 11 Eric Douglas <e.d.programmer@gmail.com> - 2019-04-03 10:34 -0700
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Date | 2019-04-03 15:53 +0000 |
| Subject | DefaultTableModel.getDataVector() and Java 11 |
| Message-ID | <slrnqa9lo4.cfl.avl@logic.at> |
In Java up to 8 DefaultTableModel had a method getDataVector() that returned a raw Vector. My application's custom TableModel overrode the method to return a Vector<MyRowType>, where MyRowType provided direct type-safe accessors for each column. In Java 11 it seems to have changed to returning a Vector of raw Vectors. At first glance this seems just goofy to me, because that doesn't really make it type-safe (it still involves a raw type), and it even prevents me from making it type-safe myself. I hope, someone here can provide me with a second glance that clarifies the rationale behind the change.
[toc] | [next] | [standalone]
| From | Patrick Roemer <sangamon@netcologne.de> |
|---|---|
| Date | 2019-04-03 18:37 +0200 |
| Message-ID | <q82ngd$u5p$1@newsreader4.netcologne.de> |
| In reply to | #38847 |
Responding to Andreas Leitgeb: > In Java up to 8 DefaultTableModel had a method getDataVector() > that returned a raw Vector. > > My application's custom TableModel overrode the method to return > a Vector<MyRowType>, where MyRowType provided direct type-safe > accessors for each column. > > In Java 11 it seems to have changed to returning a Vector of > raw Vectors. > > At first glance this seems just goofy to me, because that doesn't > really make it type-safe (it still involves a raw type), and it even > prevents me from making it type-safe myself. > > I hope, someone here can provide me with a second glance that > clarifies the rationale behind the change. API doc for this method in Java 8: "Returns the Vector of Vectors that contains the table's data values." There's quite a few occurrences of casts such as "(Vector)dataVector.elementAt(row)" in the DefaultTableModel code, too. So it seems that using another element type than Vector with DefaultTableModel has never really been a safe option, and the change only codifies to types what the contract has always been saying. Custom [Abstract]TableModel to the rescue... Best regards, Patrick
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Date | 2019-04-03 16:41 +0000 |
| Message-ID | <slrnqa9ohd.cfl.avl@logic.at> |
| In reply to | #38848 |
Patrick Roemer <sangamon@netcologne.de> wrote: > Responding to Andreas Leitgeb: >> In Java up to 8 DefaultTableModel had a method getDataVector() >> that returned a raw Vector. >> >> My application's custom TableModel overrode the method to return >> a Vector<MyRowType>, where MyRowType provided direct type-safe >> accessors for each column. >> >> In Java 11 it seems to have changed to returning a Vector of >> raw Vectors. >> >> At first glance this seems just goofy to me, because that doesn't >> really make it type-safe (it still involves a raw type), and it even >> prevents me from making it type-safe myself. >> >> I hope, someone here can provide me with a second glance that >> clarifies the rationale behind the change. > > API doc for this method in Java 8: "Returns the Vector of Vectors that > contains the table's data values." There's quite a few occurrences of > casts such as "(Vector)dataVector.elementAt(row)" in the > DefaultTableModel code, too. > > So it seems that using another element type than Vector with > DefaultTableModel has never really been a safe option, and the change > only codifies to types what the contract has always been saying. Custom > [Abstract]TableModel to the rescue... Thanks a lot - it now makes sense with that background. Will see what I really need beyond AbstractTableModel.
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2019-04-03 12:44 -0400 |
| Message-ID | <q82ntq$38c$1@dont-email.me> |
| In reply to | #38847 |
On 4/3/2019 11:53 AM, Andreas Leitgeb wrote:
> In Java up to 8 DefaultTableModel had a method getDataVector()
> that returned a raw Vector.
>
> My application's custom TableModel overrode the method to return
> a Vector<MyRowType>, where MyRowType provided direct type-safe
> accessors for each column.
>
> In Java 11 it seems to have changed to returning a Vector of
> raw Vectors.
>
> At first glance this seems just goofy to me, because that doesn't
> really make it type-safe (it still involves a raw type), and it even
> prevents me from making it type-safe myself.
>
> I hope, someone here can provide me with a second glance that
> clarifies the rationale behind the change.
Just an untested thought: Could MyRowType extend Vector,
or even Vector<T>?
--
esosman@comcast-dot-net.invalid
Six hundred fifty-eight days to go.
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Date | 2019-04-03 17:33 +0000 |
| Message-ID | <slrnqa9rj9.cfl.avl@logic.at> |
| In reply to | #38850 |
Eric Sosman <esosman@comcast-dot-net.invalid> wrote: > On 4/3/2019 11:53 AM, Andreas Leitgeb wrote: >> I hope, someone here can provide me with a second glance that >> clarifies the rationale behind the change. > Just an untested thought: Could MyRowType extend Vector, > or even Vector<T>? "Vector<Vector>" isn't the same as "Vector<? extends Vector>" (despite the theory, I tried anyway, and got the expected error that Vector<TestVectorSubclass> is indeed not convertible to Vector<Vector>) Patrick's advice to use AbstractTableModel already solved that one for me. PS: Some comment for private method "justifyRows" of DefaultTableModel that I noticed only in the course of changing to AbstractTableModel reveals developers' intention: " // Sometimes the DefaultTableModel is subclassed " // instead of the AbstractTableModel by mistake. Yep, I was guilty of that - fixed now in my code.
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2019-04-03 11:22 -0700 |
| Message-ID | <ff666f17-993d-4479-85f7-ed83c1f51ca8@googlegroups.com> |
| In reply to | #38853 |
On Wednesday, April 3, 2019 at 1:33:38 PM UTC-4, Andreas Leitgeb wrote: > PS: > Some comment for private method "justifyRows" of DefaultTableModel > that I noticed only in the course of changing to AbstractTableModel > reveals developers' intention: > " // Sometimes the DefaultTableModel is subclassed > " // instead of the AbstractTableModel by mistake. > Yep, I was guilty of that - fixed now in my code. I may have just found that note myself at some point, that the DefaultTableModel is not intended to be overridden. I knew there was a reason I ended up extending the AbstractTableModel, while I know I initially tried to extend the default which seemed like it should be less work.
[toc] | [prev] | [next] | [standalone]
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Date | 2019-04-03 18:49 +0200 |
| Message-ID | <q82o7b$59l$1@dont-email.me> |
| In reply to | #38847 |
On 2019-04-03 17:53, Andreas Leitgeb wrote: > In Java up to 8 DefaultTableModel had a method getDataVector() > that returned a raw Vector. > > My application's custom TableModel overrode the method to return > a Vector<MyRowType>, where MyRowType provided direct type-safe > accessors for each column. > > In Java 11 it seems to have changed to returning a Vector of > raw Vectors. > > At first glance this seems just goofy to me, because that doesn't > really make it type-safe (it still involves a raw type), and it even > prevents me from making it type-safe myself. > > I hope, someone here can provide me with a second glance that > clarifies the rationale behind the change. > Well, /unless/, indeed, your intent is to override, it strikes me that: Object cell = tableModel.getDataVector().get(0).get(0) is more user-friendly than Object cell = ((Vector<?>) tableModel.getDataVector().get(0)).get(0) -- DF.
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2019-04-03 10:34 -0700 |
| Message-ID | <778656f9-94e9-4dbe-be40-1f65c70008d8@googlegroups.com> |
| In reply to | #38847 |
On Wednesday, April 3, 2019 at 11:53:51 AM UTC-4, Andreas Leitgeb wrote: > In Java up to 8 DefaultTableModel had a method getDataVector() > that returned a raw Vector. > > My application's custom TableModel overrode the method to return > a Vector<MyRowType>, where MyRowType provided direct type-safe > accessors for each column. > > In Java 11 it seems to have changed to returning a Vector of > raw Vectors. > > At first glance this seems just goofy to me, because that doesn't > really make it type-safe (it still involves a raw type), and it even > prevents me from making it type-safe myself. > > I hope, someone here can provide me with a second glance that > clarifies the rationale behind the change. It would seem I never found DefaultTableModel all that useful. I have a class which contains the values needed to display one cell which just implements Comparable and Serializable. Then I have a table model class which extends AbstractTableModel with an ArrayList variable. Each element of the ArrayList contains a custom class which represents one row, constructed from a hard array [] of custom cell objects, implementing Comparable. The custom table model class has a getRow method which returns a row class instance. The custom row class has a getRowData method returning the entire array of cell data as well as a getColumnData method to return a single cell.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web