Edit column with stylename - java

I have a celltable with some columns, and want make 2 of them hidden, I tried to make a celltable column hidden, while doing following with css stylename:
firstColumn.setCellStyleNames("hide");
css:
.hide{
display:none;
}
but I get only the rows hidden, but not the header of the column, and the table not passed to the rest column, but there is still a white space on the column, I want to get hide all column with it header, how can I do it, any suggestion please?

The .setCellSomething will have effect only on the inner rows, not on the header. For that, use .setHeaderSomething, so:
firstColumn.setHeaderStyleNames("hide");
Gwt Project Docs - setHeaderStyleNames

Related

Does NatTable need a manual refresh after repaintCell?

I have the following code snippet.
int index = getEventList().indexOf(myObj);
SelectionLayer selectionLayer = getGlazedListsGridLayer()
.getBodyLayerStack().getSelectionLayer();
getNatTable().repaintCell(0,selectionLayer.getRowIndexByPosition(index));
When I run the code shown above, the affected cells only get repainted after I click on the table displayed in the GUI. If I comment out that code and use getNatTable().refresh(); it repaints without me having to first click on the table.
Is there a way to have a cell repainted without having to click on the table displayed in the GUI? I would hate to have to call refresh() for a large table where this code may be executed many times.
No you don't need to perform some additional step in order to trigger the repainting. The issue in your code is the usage of wrong index values. You have a grid so column 0 is the row header from the NatTable perspective. I suppose you want to redraw the first column of the body, which is index 1 from the NatTable point of view. Also the row index is incorrect, as you calculate the index in the SelectionLayer but actually need the index in the table, which is at minimum +1 if you only have a column header row.
Actually your code should work by adding 1 on the index if you have one row header column and one column header row in the grid.
getNatTable().repaintCell(1, selectionLayer.getRowIndexByPosition(index) + 1);

How to hide the Jtable column data?

I want to hide data of a column of Jtable, but not hide the column view,just its data.
The column contain data about profit and the customer doesn't want to show the profit but in my code I use the values of this column and get it when the user select specified row.
How do I achieve the customer need and still be able to get the values of this column when selecting it after hiding its data(displaying column as empty but still has its values)?
You need to remove the TableColumn from the TableColumnModel of the JTable. For example:
table.removeColumn( table.getColumn(...) );
Now the column will not display in the table, but the data is still available in the TableModel. to access the data you use:
table.getModel().getValueAt(...);
You could try a subclassing DefaultTableCellRenderer, and call setCellRenderer. When the relevant column number is passed to getTableCellRendererComponent, return a blank JLabel, otherwise call the default super.getTableCellRendererComponent.
This should mean the column is still visible, but each cell will be blank.
If you want to display the data when a row is selected, you will need add a listener to the selection model (from getSelectionModel) to store the selected row in a variable, and call a repaint. You can then use this value in your CellRenderer.
Why don't you just let the dataModel control what is shown? I'm assuming you are using a tableModel.
All you have to do is change the getValueAt(..) method so that it does not return a value for the column you do not want to show. Make sure that getColumnCount() method is reduced by one as well.

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

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.

How to add row header to JFace TableViewer?

How can I add "row headers" to a Jface TableViewer?
Have a look at the Grid widget from the Nebula Project.
It does support "row headers".
A TableViewer does not by default provide this capability. But you can have a look at this snippet to achieve something similar to a row header. This example uses two tables to make the first column fixed and rest of the columns horizontally scrollable. If you do not want fixed columns than you can just use different colors for columns to achieve the look and feel of a row header.

Remove JTable Column identifier

I wan' t to customize the apparence of my JTable. I wan' t to remove the column identifiers that's hold the column name. I don' t want to simply leave it blank but I wan't to "hide" that. any suggestion? thanks!
You can hide the table header this way:
table.getTableHeader().setVisible(false);
Or you can remove it entirely:
table.setTableHeader(null);

Categories