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.
Related
How can I add summary row in TableViewer (or different Viewer from SWT), which (row) will be containing sum of all rows in proper column?
And by the way, the next question. Is it possible to set multiline header in TableViewer?
Thanks
There is no special way to do this.
Your table Content Provider will have to return an object containing the summary data.
I want to render different swing components in the same JTable column. For example, I want to have few different comboboxes, jlabels and jcheckboxes in the same column. http://docs.oracle.com/javase/tutorial/uiswing/components/table.html provides information how to render only one type of combobox per column, however it is not enough.
How can I setup table cell renderer so that it would achieve this functionality?
If you need to use different editors/renderers in the same column, you can follow the approach described in this answer and override JTable#getCellEditor() based on the cell (column and row intersection). JTable#getCellRenderer() can be overriden if needed as well.
In Concepts: Editors and Renderers is described the strategy followed by tables to get a renderer/editor so you can take advantage of it to solve your problem.
I want to be able to do two things:
set colors of rows based on index, so first row is red, second blue,
third green
be able to set color of columns also based on something, be it index
or their names etc, whatever is possible.
I do not need to detect selection change or anything. Could someone tell me how to do that? What methods would help etc? In case the title wasn't read, this is regarding DefaultTableModel in JTables.
set colors of rows based on index,
Table Row Rendering might give you some ideas.
be able to set color of columns also based on something
You can provide a custom render for any column. Then you can add you logic to color the column based on something. Read the JTable API and follow the link to the Swing tutorial on How to Use Table and you will find a section on creating a custom renderer.
Is it possible to get multiline (say 2-line) row in JFace tableViewer? I want my long text part spreaded between two lines, and my short lines aligner vertically in the cell. How can I achive that result?
The table control itself does not support this. You will have to paint the content of those cells yourself. There's an official example (Snippet006TableMultiLineCells) on how to do that.
How can we show/hide some columns in JTable?
I recommend JXTable from the SwingX project, hiding columns in the view is very easy:
table.getColumnExt(index).setVisible(false);
JXTable also provides a column control(menu in top-right corner) where user by them selfs can hide/show columns.
When using JXTable from the SwingX project, as suggested by Uhlen,
It's better to use
table.getColumnExt("columnName").setVisible(true);
table.getColumnExt("columnName").setVisible(false);
the index when using getColumnExt(index)is the column index that is in the view (i.e.visible)
Once you set a column invisible, you can't access to it by getColumnExt(index)
Instead of having to loop through the list for every cell call as shown at codeGuru, you could change the columnModel to switch the column-visibility by setting from/to zero-width and setting editable/noneditable. That wat default handling skips over that column.
You can find a sample at codeguru:
http://www.codeguru.com/java/articles/660.shtml
Don't forget that google is your best friend ...