Row header in JTable with same drag/drop behaviour as column header - java

I'm trying to have row headers in my JTable which have similar behaviour to the column headers, especially for the drag and drop part.
Something like this: JTable Row Header Implementation
And when I drag the row header, it should have the same visual effect as when I drag the column header and the same result (row/column is moved).
So far, one way I thought of is to create my own custom BasicTableHeaderUI and implement the paint() method. Not sure if that will cause problems if other look and feels were used?

You can add D&D listener to table cells or whole table, and than pass the event to EventHandler that handles D&D events on header.

Related

Make JTable Column Header Not Movable/Resizable

Whatever I try I cannot get a JTable's header to be static. Right now you can click in the headers and drag them out or just relocate the entire columns of the table by moving the header.
Is there a way to prevent this and make the headers not editable?
Just to be clear I am not talking about the actual cells but the headers.
The class JTableHeader has a method
setReorderingAllowed(boolean reorderingAllowed)
did you try that already, or does it maybe help you with your problem?

Using combobox as column header in javafx tableview

I am working with javafx2.2 and want to this thing don't know whether something already exist or not.
I need to add combobox to column header of a tableview but I want to retain functionality of clicking header and sort my data.
I know I can attach combobox using TableColumn.setgraphic(ComboBox); and use width of combobox and tablecol accordingly and have combobox on top of my column header but I don want this.
I want combobox to take complete space of my columnheader but with functionality of sorting on click.
Is it achievable? If yes then how?

Disable particular rows of a JTable

I would like to "grey out" particular rows of a JTable so that they may not be selected by any means. The other rows should still be selectable. How do I accomplish this?
You can either override JTable.changeSelection() to deselect the offending row whenever it's selected, or provide your table with a custom ListSelectionModel where you override setSelectionInterval(), addSelectionInterval(), etc. to prevent the row from being selected in the first place.
You will want to create a custom TableCellRenderer, one that will display "disabled" information greyed out. Read the Swing Table Tutorial for more on how to create these renderers, especially the section, Concepts: Editors and Renderers.
Create a temporary TableModel which has only the rows that you want to select. After the selection made and when you want to revert, change back to original TableModel

Disable a single column dragging in JTable

How should I disable just a single column from dragging in JTable? I want to allow other columns from dragging but just the first column (indexed at 0). Thanks.
You should be able to create your own TableColumnModel (extend DefaultTableColumnModel) and to override moveColumn to only call super.moveColumn when the column is allowed to be dragged.
EDIT: Have a look at this post first.
Not quite on point for you ....found on another blog
yourJTable.getTableHeader().setReorderingAllowed(false)
this gets the entire table not to reorder columns which is what I needed. Exploring the Override is the correct route

JTable onchange event

Is there any way to detect a cell selection change in a JTable? I've found documentation for detecting a row change using ListSelectionListener but it doesn't seam to work when changing selection on the same row. I'm using JTable to render a simple schedule.
Maybe I should use a different component?
No, the right component for showing tabular data is JTable.
You want to add a listener to the TableModel that's underneath the table. That will fire off events whenever data changes. You get it out of JTable, unsurprisingly enough, by calling getTableModel().
Update
Oh wait, I think I misunderstood you. You're not interested in data changes but column selection changes.
JTable has a method called columnSelectionChanged; its documentation says it's called by TableColumnModelListener, which leads me to believe that what you want to do is getColumnModel() and use the addColumnModelListener() method of that to listen for column selection changes.

Categories