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


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

Re: Sort a jtable within code

From "John B. Matthews" <nospam@nospam.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Sort a jtable within code
Date 2012-09-13 23:58 -0400
Organization The Wasteland
Message-ID <nospam-DFA37D.23580513092012@news.aioe.org> (permalink)
References <114c9b7c-7ed8-4f59-aa46-c7480a677be7@googlegroups.com> <nospam-03FC5A.21124012092012@news.aioe.org> <f8e3b99f-0790-4d51-a25d-fef63576a936@googlegroups.com>

Show all headers | View raw


In article <f8e3b99f-0790-4d51-a25d-fef63576a936@googlegroups.com>,
 Lew <lewbloch@gmail.com> wrote:

> John B. Matthews wrote:
>> Have you looked at Sorting and Filtering?
>> <http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting>
> 
> Oh, I like that site. Thank you.

You are welcome. Many articles saw updates during the run-up to the 
Java 7 roll-out. It's also an appealing example of integrating Java Web 
Start.
 
> > You can restore your TableModel's intrinsic order as shown here:
> > <http://stackoverflow.com/a/5484298/230513>
> 
> I'd like to know your preference regarding the tutorial example 
> 
> <http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.orac
> le.com/javase/tutorial/uiswing/examples/components/TableSortDemoProject/src/co
> mponents/TableSortDemo.java>
> 
> (and ain't the "tutorial/displayCode.html" cool, huh?)

Yes, although it took me a while to understand the "Download" link.
 
> Do you prefer
> 
>   public class TableSortDemo extends JPanel {
>     public TableSortDemo() {
>       super(new GridLayout(1,0));
> 
> as they do it, or 
> 
>   public class TableSortDemo {
>     JPanel sorterPanel = new JPanel(new GridLayout(1,0));
> 
> etc.?

Ideally, I try to follow Joshua Bloch, Effective Java, 2nd edition:

Item 16: Favor composition over inheritance

Practically, a JPanel is a convenient unit of containment and a handy 
rendering surface, so I may honor item 16 more in the breach than the 
observance. I can't fault other weaknesses in the tutorial too much; 
the particular example cited predates annotations and generics, both 
introduced in Java 5.

Item 17: Design and document for inheritance or else prohibit it.

The parent, JComponent, is a good example of the former. JPanel adds 
very little: opacity, a default layout and a UI delegate.
 
> Also, 
> 
>   public Class getColumnClass(int c) {
>     return getValueAt(0, c).getClass();
>   }
> 
> 'Class<?>' or don't bother?

Citing the same source, Item 23, the unbounded wildcard type Class<?> 
"is safe and the raw type isn't." Checking 22 Java 1.5+ examples, I've 
(carelessly) used the raw type twice.

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

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


Thread

Sort a jtable within code clusardi2k@aol.com - 2012-09-12 06:25 -0700
  Re: Sort a jtable within code Martin Gregorie <martin@address-in-sig.invalid> - 2012-09-12 19:39 +0000
  Re: Sort a jtable within code Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 20:48 -0400
  Re: Sort a jtable within code "John B. Matthews" <nospam@nospam.invalid> - 2012-09-12 21:12 -0400
    Re: Sort a jtable within code Lew <lewbloch@gmail.com> - 2012-09-12 22:51 -0700
      Re: Sort a jtable within code clusardi2k@aol.com - 2012-09-12 22:58 -0700
        Re: Sort a jtable within code clusardi2k@aol.com - 2012-09-13 07:53 -0700
      Re: Sort a jtable within code "John B. Matthews" <nospam@nospam.invalid> - 2012-09-13 23:58 -0400

csiph-web