Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2006

Tip: Looking for answers? Try searching our database.

Sorting JTable with fixed column

Thread view: 
domenico.test@gmail.com - 19 Feb 2006 17:06 GMT
I need to make a jtable with these requirements:
- The first two columns fixed
- It should sort the rows by clicking on the headers name

By clicking on the column header both columns need to be sorted
zero - 19 Feb 2006 18:25 GMT
domenico.test@gmail.com wrote in news:1140368789.831896.67720
@g14g2000cwa.googlegroups.com:

> I need to make a jtable with these requirements:
> - The first two columns fixed
> - It should sort the rows by clicking on the headers name
>
> By clicking on the column header both columns need to be sorted

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

The discussion includes a way to sort columns, which should be exactly what
you need.  JDK 1.6 should include this behaviour as standard, previous
versions can use the code from the tutorial verbatim.

To make the first two columns uneditable, extend DefaultTableModel:

public class MyTableModel extends DefaultTableModel
{
  public boolean isCellEditable(int row, int column)
  {
     return column >= 2;
  }
}
domenico.test@gmail.com - 20 Feb 2006 08:54 GMT
zero ha scritto:

> domenico.test@gmail.com wrote in news:1140368789.831896.67720
> @g14g2000cwa.googlegroups.com:
[quoted text clipped - 20 lines]
>    }
> }

Yes, I had see the exaple but i need that the first two columns are
fixed and the other scroll.
e.g.
The table have 6 columns and 4 are diplayed.

---------------------------------
| Col 1 | Col 2 | Col 3 | Col 4 |
|       |       |       |       |
   scrollbar ->  <------------->

Using the scrollbar the first two columns are displayed with the column
5 and 6

---------------------------------
| Col 1 | Col 2 | Col 5 | Col 6 |
|       |       |       |       |
               <-------- ------>
zero - 23 Feb 2006 19:30 GMT
> zero ha scritto:
>
[quoted text clipped - 41 lines]
>|       |       |       |       |
>                 <-------- ------>

I have never tried anything like this.  I think you would need to write
a custom UIManager, or maybe a custom JScrollPane.  I'm not sure how to
get started on this though.  Perhaps a different approach would be
feasible, such as two separate JTables side by side, or some other
workaround.

You may get a better reply at sun's own java forums.  The swing forum
can be found at http://forum.java.sun.com/forum.jspa?forumID=57

I would be interested in any solution you come up with.
hiwa - 23 Feb 2006 23:38 GMT
> first two columns are fixed
See links found on this page:
http://www.javaworld.com/javaforums/showthreaded.php?Cat=&Board=javabeginner&Num
ber=26604&page=&view=&sb=5&o=&vc=1

hiwa - 23 Feb 2006 23:42 GMT
>  - It should sort the rows by clicking on the headers name
Use JTable and new support classes found on JDK 1.6 (or 6).


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.