Solved

How to disable the Movement of JTable Column

Posted on 2000-04-25
4
435 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

691 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