I have a large table to display in one of our Vaadin application. The table has 110 columns with large text header for each column.
On display the table looks awful as all the column header goes off the screen and the header separator loses the alignment with the data record column separator.
I have set the table width to 100% to display the table scrollbar. I tried to set columnExpandRatio as well as column width but no success.
Vaadin table by default sets the text header width as the column width. Is there any way i can set the header/column width to fit my data rather the header?
Finally as a solution I assigned no width value to initial columns (like first 30 columns will span naturally) and later columns with fixed width size with setColumnWidth() and it worked.
Please use table column name hide which s very useful for the viewer can choose what are the column he is able to view ...
http://demo.vaadin.com/sampler/#TableRowHeaders
Related
I have a custom table with dynamic width and height for each column and row. I also planning to use JTextField as TableCellRenderer.
Should I set the table row height and column width inside the render or inside the custom table?Or there is another place that I can place this?
You can use JTable#setRowHeight(int, int) to set the height of individual rows and you will need to use the ColumnModel and obtain a reference to the TableColumn in order to change it's size.
Remember though, the size of a column may be affected by the autoResizeMode
I am using JXtable in my project.When I double click some column,it will be expanded or contracted to the highest character cell in that column. Is there any way of creating JXtable so that all its columns shall be resized to the size of its highest character cell.
I'm not sure I understand correctly, but to programmatically resize all columns according to their contents you can use JXTable.packAll();.
packAll() Javadoc:
public void packAll()
Resizes all columns to fit their content.
By default this method is bound to the pack all columns Action and registered in the table's ActionMap.
This will make the column with the "broadest" content the biggest, the column with the second "broadest" content the second biggest and so on. I am using it in my projects and it works quite well.
Resizing can also be achieved by clicking on the according menu item from the table controls.
You can use the Table Column Adjuster which will automatically adjust the width of a column any time the data is changed.
I would like to create a Table something like this:
I hope the picture is good enough. If a scrollpane is activated only the cells shall move and header and subheader keep to stay at their place. How do I do this with JList or JTable? Or is there another component? Thanks a lot
easier and possible by using JTable, rather than JList, see RowHeader
based on #camickrs Row Number Table
One approach could be to have 3 different tables.
For the header to stay in place when you scroll the cells, you can create 2 tables. One will contain only the header (without cells) and would be in the north position of a border layout in a JPanel. In the center position of the JPanel you would add a JScrollPane with a table and you would need to remove the header for it, so that the displayed header for the table would be the one of the table in the north position.
For the "subheader" you would need another table, with only one column and a header renderer added to that column. That table should be in the west position of the JPanel.
Finally you would need to synchronise the header of the north table with the columns of the center's one, so when it is resized the columns of the other are as well. If the table is sortable you would need to do the same with the table in the west position.
A better option can be to use TableScrollPane from JIDESoft, that does all this and more behind the scenes, but is paid.
Your choice.
I am making a dialog for the purpose of selecting multiple file paths. My dialog consists of two panels. One for buttons such as "Add" and "Remove", and a second panel containing a JTable wrapped in a scrollPane. The table has only one column. The cells of the table are not editable directly. When a user selects a file using a JFileChooser, the full path of that file will be added to the table. Although my dialog is resizeable, I still need a horizontal scroll behavior in the event that the file path is longer than the user's screen is wide.
I have researched the combination of resizeable table and horizontal scroll bar. That is similar, but not my issue. The typical scroll behavior is that the columns are scrolled, not the contents of the columns. I need the contents of a single column to scroll horizontally.
doesn't matter whether you scroll a multiple or only a single column: the basic issue is to get the horizontal scrollBar to start with :-)
There are two screws to tweak:
- enable horizontal scrolling by setting the table's resizeMode: default is to always fit the table's size to the size of the scrollPane, that is no scrolling
- resize the column width to fit its content
In a core JTable that maps into pseudo-code like
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// on receiving a TableModelEvent which might increase the column width
// calculate new width by measuring pref of the renderer
int newWidth = ...
// set it as pref of the column
table.getColumnModel().getColumn(0).setPreferredWidth(newWidth);
The catch is that without resizeMode, you are always responsible to sizing the column: it its width is less than the scrollPane, there's an empty region at its trailing side.
JXTable (part of SwingX project), supports an addition sizing mode which fills the available horizontal space as long as the table's prefWidts is less than parent width and shows a horizontal scrollBar if needed
table.setHorizontalScrollEnabled(true);
// on receiving a TableModelEvent which might increase the column width
// tell the table to re-evaluate
table.packColumn(0);
I selected kleopatra's answer as correct because it addresses my specific question regarding table manipulation. I am adding this answer because I ended up solving my root problem in a different manner.
I chose to use a JList to represent my file paths instead of a single column table. The only real reason that I had wanted to use the JTable was because of the appearance of the lined rows that a table has, and because of my unfamiliarity with JList. I discovered how to edit the appearance of the JList by extending the DefaultListCellRenderer. Because I now knew about editing the appearance, the JList's natural resizing and scroll behavior made it a much more natural fit to my needs.
Im creating a table which is dynamically changing its width. And I add columns by time as well. And I have bounded this table to a scrollpane. Here I have set the auto resizing to false in the JTable (else it will fill the whole area from the beginning).
And I'm adding images to cells using cellrenderer as well. Now I need to allow users to resize this table columns.
Any idea?
I don't understand the question, by default the user is allowed to resize the columns by dragging the header of the column.
However if you want this to happen automatically then you can try using the Table Column Adjuster, which can automatically adjust the columns to fit the size of the data.
Well first of all - just change TableModel. You can leave column resizing on and for example set maximum width of cell by using setMaxWidth
Or just pick correct mode that fits your requirements. You can find them here.