Solved

How to disable the Movement of JTable Column

Posted on 2000-04-25
4
431 Views
Last Modified: 2008-02-20
JTable has a useful function that the User can move any Column as the like and JTable can reorganize it automatically. But for some reason,I need to disable this function. How can I do?

Now My method is:
  class CustomModel extends DefaultTableModel {
        public CustomModel(Object[][] data, Object[] columnNames) {
              super(data, columnNames);
        }
        public Class getColumnClass(int col) {
            // dataVector is a protected member of DefaultTableModel

              Vector v = (Vector)dataVector.elementAt(0);
              return v.elementAt(col).getClass();
        }
    public boolean isCellEditable(int row, int column) {
      if(column < 3)
        return false;
      else
        return true;
    }

  }
  CustomModel dataModel = new CustomModel(data,names);
  JTable tblData = new JTable(dataModel);

But when using TableColumnModelListener,
it report an error.

Thank you very much.
0
Comment
Question by:EdwardWong
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
sankars98 earned 25 total points
ID: 2747805

 table.getTableHeader().setReorderingAllowed( false );

  this would do..

> But when using TableColumnModelListener, it report an error.

 What error are you getting and how do you use it?

Sankar S.
0
 

Author Comment

by:EdwardWong
ID: 2749934
> But when using TableColumnModelListener, it report an error.

What error are you getting and how do you use it?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I use
"table.getColumnModel().addColumnModelListener ( new tableColumnModelListener () {
.........}); "

in init() Function.
The java compiler reports an error, as below:
Anonymous class of method jbinit() should be declared abstract, it does not define method columnSelectionChanged(javax.swing.event.ListSelectionEvent) in Interface javax.swing.event.TableColumnModelListener.

Thank you for your help.
0
 
LVL 1

Expert Comment

by:sankars98
ID: 2751202

>Anonymous class of method jbinit() should be declared abstract, it does not define method columnSelectionChanged
>(javax.swing.event.ListSelectionEvent) in Interface javax.swing.event.TableColumnModelListener.

  It seems you have not implement the
  TableColumnModelListener() properly.

  You have to implement all the functions(5) in TableColumnModelListener when you try to implement this interface.

 table.getColumnModel().addColumnModelListener( new TableColumnModelListener(){

 public void columnAdded(TableColumnModelEvent e){}

 public void  columnMarginChanged(ChangeEvent e){}

 public void columnMoved(TableColumnModelEvent e){}

 public void  columnRemoved(TableColumnModelEvent e){}

 public void columnSelectionChanged(ListSelectionEvent e){}

});
 
Sankar S.

0
 

Author Comment

by:EdwardWong
ID: 2751299
No, I implement all the functions(5) in tableColumnModelListener, As below:

table.getColumnModel().addColumnModelListener( new TableColumnModelListener(){

 public void columnAdded(TableColumnModelEvent e){}

 public void  columnMarginChanged(ChangeEvent e){}

 public void columnMoved(TableColumnModelEvent e){
table.getTableMode()...
^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

 public void  columnRemoved(TableColumnModelEvent e){}

 public void columnSelectionChanged(ListSelectionEvent e){}

});

I think if in the Implementation Java doesn't allow user to cite the table it self.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question