I have four JTables arranged in a 2x2 square. I want the columns and rows to be connected: when a column on one table is rearranged or resized (by the user or otherwise), I want the same things to happen to the table above or below (in real time); when rows or columns are sorted or highlighted, I want the highlighting to happen in the adjacent table, forming a continuous line of selection.
To the right, the numbered columns are the start of new tables (four tables in all)
To synchronize scrolling, the vertical scroll bars of separate scroll panes can share a common BoundedRangeModel. To synchronize selection, separate tables can share a common ListSelectionModel. The table models must be commensurate. There's an example showing two tables in this Q&A.
Related
I'm transitioning some tables from Swing to FX.
I am trying to create a custom horizontal oriented TableView kind of like what is asked about here.
I utilized this method to wrap and display my column of data. I did a bind between two table scrollbars to get a "row header". Here is what the entire thing looks like:
Then I checked how well TableView handled loading a large amount of data. I created a basic multiplication table with 10 columns and 100,000 rows. After the initial load-in, the table was incredibly responsive and the vertical scrollbar movement and had no issue.
My issue came when I add more columns. I believe because of the way that TableView expects data to be in rows instead of columns that when I add 10,000 columns and 50 rows the entire TableView component was unresponsive. It also took significantly longer to load-in than the 10 columns, 100k rows.
At ~4k columns and 50 rows, the table responded well to the horizontal scroll, but the vertical was very slow to respond, which is why (apart from the inherent structure) I was lead to believe TableView prefers row data to column.
Is there a way around the unresponsiveness that preferably:
Keeps the columns as the dataset
Doesn't involve going back to JTables
Avoids pagination
I found this post, but it did not seem helpful and the OP went back to JTables in the end. On the other hand, this was 4 years ago and a slightly different case.
Please note I am new to posting so let me know if more info is needed.
I've build an application in Java with the help of JFace/SWT. I am using mainly the TableViewer of JFace and sometime the SWT table behind with myTableViewer.getTable().
My table has a header (filled with the column names) and the first row is rendered with CCombos in CellEditors (drop down menus for filters).
Now I want to fix this first row ("filter-row") in the table, so it is always shown, independently if I am scrolling down or not..
Do you know any opportunity to do this (instead of splitting one table in two tables, as I found it in the internet)?
The SWT Table does not support fixed rows or columns.
If the combos were inteded to hold a limited number of choices you may use context menus on the column headers instead.
There are also alternative Table-like implementations in varying degrees of maturity that you may consider:
Nebula Grid
XViewer
NatTable
If non of the above fits your requirements you will have to either use a distinct table that holds the combo widgets or implement a custom 'header' control.
I'm trying to find a way to make a Java table (Swing component) that can wrap the list of columns into multiple lines per row.
/[ Column Hdr A ][ Column Hdr B ]
Hdr |[ Column Hdr C ][columnHdr D ][ColumnHdr E ]
\[ column Hdr F ][COlhdr G][colhdr H][CH I]
/[ Cell 1 A ][ Cell 1 B ]
Row 1|[ Cell 1 C ][cell 1 D ][Cell 1 E ]
\[ Cell 1 F ][Cell 1 G][Cell 1 H][C 1I]
...
Where each column size is independent of any other. IE: I'm not doing spanning or column header grouping. It should retain the column resizing, hiding and sorting features. Drag and drop re-ordering would be nice but isn't necessary.
So I've searched everywhere for something like this. All I've found are various schemes for spanning cells or using fixed width sub-columns. There was one person who claimed to have done it by overriding getRect, but there was no code to look at, so I'm not sure how that would work wrt to resizing or hiding columns, and how would you specify which columns went where?
I've considered just extending TableColumn to include a "sub-row" property but that means also having custom TableColumnModel, JTableHeader and Jtable, AND Jpanel. And I suspect that the renderer and all the LookandFeel UIs would also have to be modified.
An ugly hack that occurred to me is to create one table per sub-row of columns, and then use some form of mutant jpanel to expose the rendered rows interleaved down the y axis. I'm not sure that would work with scroll bars though.
So, does anyone have a neat, concise way to implement this? Any suggestions about how to proceed?
I would hope that you would re-organize the output to be more human readable. While this does fit the data onto the page, a human reading it would have a great deal of problems trying to understand what table cell belonged to what header and which row was which.
Can you create rows with only the 'important' data visible first, then the user could click (or some gesture) to open the more detailed results? Or include multiple cell values together in a multi-line cell to reduce the data to a single row per record?
This gives you two great benefits. First the data will be understandable at a glance, and second, you can use the existing table implementations and save yourself the significant development work.
Finally, have you tried using an HTML widget to display the data? You could create the table as divs in HTML and have the widget wrap the rows. Then you could style the cells for each column to be a fixed width.
I can't offer you any code, but you could look into customizing the table model (class MyTableModel extends AbstractTableModel {...}).
The approach could be to overload the SetValueAt(Object value, int row, int col) method so that writing row 1, col 3 for example would actually write row 2 , col 1 and so on to display multiple lines for 1 line of you data table
Do you indeed need the behaviour which prevents some columns from scrolling?
It is a quite standard usability solution. I would recommend you to come up with a dialog allowing to hide and freeze columns. In this case users could organize the viewport the way they feel best at the moment. Here is an example of scroll freezing.
The second option may well be HTML. You can generate whatever you want this way. Though this solution may have a limitation if you need to edit your data.
Ergonomics uggestions:
Is it acceptable to present headers or data vertically? Sometimes it is better readable.
Basically JTable supports adding swing components including nested tables or cells. please refer to the ff links
com.lang.java.gui discussion
a similar thread
Is there a way to make, let say first 3 out of 7, columns fixed in Cell table. I want to be able to see always first three columns and have horizontal scroll on others.
You will have to create a custom widget that consists of a ScrollPanel, which includes two CellTable widgets set side by side. The right table should be wrapped in a FlowPanel with overflow-x property set to AUTO (overflow-y should remain at HIDDEN).
You can use the same DataProvider for both tables to synchronize all changes. Be careful with the SelectionModel though, if you need it. I would limit selection to the first column of checkboxes and disable selection by clicking on a row.
Make sure that your widget fits into its space, or you may end up with two horizontal scrollbars - one for the ScrollPanel and one for the right table. Finally, remember to set sizes on both tables so that they have the same height.
I have a JTable consisting of multiple rows and columns. I want to make the cells selectable, but only in one row at a time. So for example, when I click on the cell in third row and the fifth column, I can pull the mouse to the left or right and select more cells, but only in this specific row and not in the row above or below.
How can I do this?
Use the setSelectionMode() method from ListSelectionModel interface, and set the selection mode to ListSelectionModel.SINGLE_SELECTION.
This will configure JTable to work with one row at a time selection, blocking selection of multiple rows.
To select single cells, combine the above with setColumnSelectionAllowed(true) on TableColumnModel, and you should get what you need.