Solved

How to disable the Movement of JTable Column

Posted on 2000-04-25
4
427 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 48
Receive file in Servlet 1 36
Unable to open debugger port in Intellij idea 6 88
Java Timer (static) 9 19
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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now