Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Restrict the User to Move a Column in a JTable Component

 
Tapan Maru
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian Cole
Author
Ranch Hand
Posts: 906
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Denross Salenga
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic