Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to disable the Movement of JTable Column

Posted on 2000-04-25
4
Medium Priority
?
439 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 75 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

609 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