wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Restrict the User to Move a Column in a JTable Component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Restrict the User to Move a Column in a JTable Component" Watch "Restrict the User to Move a Column in a JTable Component" New topic
Author

Restrict the User to Move a Column in a JTable Component

Tapan Maru
Ranch Hand

Joined: May 08, 2006
Posts: 65
Hello,

I am having a JTable which is instantiated from a TableModel (subclassing AbstractTableModel).

In that table I am having first column of date-time and all other columns of some double values.

Later I am plotting a graph from that table in which date-time column Column at an index 0) is the domain axis for graph and all other columns becomes range axis of the graph.

Now i want that user should not be able to move first column. all other columns can be rearranged in the table.

Is there any way to restrict the user by disabling movement of the first column?

Please Help if any of you had came across such an issue.

Thanks in advance,


Tapan Maru
tapanmaru@gmail.com
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

You know, Tapan, I googled JTable fixed column and got more hits than I could read in a lifetime. And most of the hits on the first page had code examples.


luck, db
There are no new questions, but there may be new answers.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by Tapan Maru:
I am having a JTable which is instantiated from a TableModel

Now i want that user should not be able to move first column. all other columns can be rearranged in the table.

Is there any way to restrict the user by disabling movement of the first column?


The simple way to handle this is by changing the behavior of the
moveColumn() method of the table's column model. For example:

This will prevent the first column from being reordered, but there may
be some visual flaws. If the user attempts to drag the second column
leftward to be the first, s/he will be prevented from doing so but may
experience some odd visual jumping. To clean that up is possible but
is more work.

Originally posted by Darryl Burke:
I googled JTable fixed column and got more hits than I could read in a lifetime.


In my experience, most people looking for a "fixed column" are worried
about scrolling, not reordering. They want one or more leftmost columns
to stay put while the horizontal scroll bar moves the others. A typical
side-effect of this is that the first column can't be reordered, but it's
a different kind of thing.
[ June 09, 2008: Message edited by: Brian Cole ]

bitguru blog
Denross Salenga
Greenhorn

Joined: Feb 07, 2010
Posts: 1
Tapan Maru wrote:
I am having a JTable which is instantiated from a TableModel (subclassing AbstractTableModel).

In that table I am having first column of date-time and all other columns of some double values.

Later I am plotting a graph from that table in which date-time column Column at an index 0) is the domain axis for graph and all other columns becomes range axis of the graph.

Now i want that user should not be able to move first column. all other columns can be rearranged in the table.

Is there any way to restrict the user by disabling movement of the first column?



Sorry for waking up the zombies but I just want to post my solution to this problem so that the future researcher with the same problem can also use this solution.^^





Cheers,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Restrict the User to Move a Column in a JTable Component