How to disable JTable column dragging?

I'm using a JTable and the user can drag columns this way changing column ordering. I want to disable it. Please provide a few lines of code which does it.

Thanks.
LVL 2
MindoAsked:
Who is Participating?
 
Jim CakalicConnect With a Mentor Senior Developer/ArchitectCommented:
Column reordering is a behavior implemented by JTableHeader. Try this:

    JTable table = <your table>;
    table.getTableHeader().setReorderingAllowed(false);

Best regards,
Jim Cakalic
0
 
bhardwajanjaliCommented:
I am ot sure what are you asking but may be the following exception helps you.
I think you want to disble the column drag property of the table. See if you want to drag a table first you need to select it and then onle you can drag it.
So why dot you try to disable the selection of the column using the following function:
void setColumnSelectionAllowed(boolean flag)

Hope this helps.

cheers,
Anjali
0
 
bhardwajanjaliCommented:
I am not sure what are you asking but may be the following discussion helps you.
I think you want to disable the column drag property of the table. See if you want to drag a table first you need to select it and then only you can drag it.
So why dot you try to disable the selection of the column using the following function:
void setColumnSelectionAllowed(boolean flag)

Hope this helps.

cheers,
Anjali
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
MindoAuthor Commented:
You didn't understand point. The user drags the column by clicking on the column header and dragging mouse. Then the user can release the mouse and the column order changes, i.e. the column is dragged to another place.

Try it using JTable and you'll understand how columns can be dragged.
0
 
terajivCommented:
Hi Mindo,
The following method may help u
void                 setColumnSelectionAllowed(boolean flag)

Rajiv
0
 
MindoAuthor Commented:
This question isn't about column selection, it's about column DRAGGING. Please, try a simple example and you'll see how the user can drag a column from one place to another. What does it have to do with column selection?
0
 
MindoAuthor Commented:
Works cool, thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.