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
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.
Generally, for GWT list views of POJOs/DTOs I typically use a ListDataProider and a CellTable and place the CellTable into a Vertical Panel with a SimplePager. All is well.
I have a scenario where the Pojo's DTO is only 3 fields; and as such it would be nice to create a list view where I can put two columns of my DTO's next to each other and page accordingly. For example, instead of just three columns per row, there would be six where the first three columns represent one DTO instance and the next three (repeated) columns represent a second DTO instance.
Has anybody successfully done this before using celltables or other GWT component? Looking for a simple approach.
My fallback position (which is good enough) was to use a FlexTable with a search form and caping the results to 40 records. Two columns of 20 DTO's.
I have done something similar. I was using a Grid. The key to align the components was this line of code:
myGrid.setWidget(position/COLUMNS_NUMBER+1, position%COLUMNS_NUMBER, lName);
Where lName was a GWT Label with the element (property) to be displayed (the 'name' property of my POJO / DTO). COLUMNS_NUMBER is my constant for how many columns I want to display.
I was displaying just this property, but you could easily adapt this idea to show more than one property of more than one DTO in different columns. My algorithm was just iterating through the DTO collection, getting each DTO's name prpoerty, which would be inserted as a Label in the Grid via setWidget, and updating the index variable position, which starts in 0.
I also needed this condition:
if(position%COLUMNS_NUMBER==0){
list.insertRow(position/COLUMNS_NUMBER +1);
}
I'm displaying only onew property of each DTO, but the idea is also not having each one in a different row, and customizing the number of columns displayed. Again, you can adapt that to meet your needs, by adapting the way you increment the index variable position and the column where you display the DTO property or (even simpler) by following the same approach and just choosing a different property to display each time depending on
postiont%3
since you want to show 3 properties of each DTO.
I'm having a trouble in accessing a Birt Cell value from another cell.
Cell #1 has dynamic text with it's expression. It's binded to a DataSet#1.
Cell #2 has dynamic text with it's expression. It's binded to a DataSet#2.
Cell #3 must use cell1 and cell2, and count an expression based on their value. Let's say cell#1.value()+cell#2.value()
The thing is, I can't find a way to get cell#1 value.
I've tried:
this.setDisplayValue(reportContext.getDesignHandle().getElementByID(997).text());
But got an error on processing
Cannot find function text in object org.eclipse.birt.report.model.api.TextDataHandle#edc8ca
It also didn't have functions like getValue, getDisplayValue
Does anybody know how to solve it?
There is not a lot of information here on your report design. But making a couple of educated guesses. Dynamic text is not the best choice for doing anything with the results afterwords. Two easier paths to solutions are -
1 - If practical join your data sources into one data source with computed columns for your values in cell 1, 2 & 3
In the Outline, right mouse click 'Data Sets' and select 'New Joint Data Set'
2 - Use a 'Data' item for cells 1 & 2, this will allow you use the 'Aggregation' item to sum (or otherwise work with) the values in the 'Data' item
In the palette of report items with 'Dynamic Text'
Hi I'm using set of classes I found on internet that extends JTable capabilities making me able to merge or split some cells.
Mentioned capability works ok but I have two problems with how the table is displayed. The extended JTable is stored in JScrollPane and it is stored in Box.
The first issue is that when I have a lot of collumns the last one or last two ( depends on how many collumns I have ) is being clipped ( when I move scrollbar to the right edge I don't see last collumn or it is clipped so only the part of the data is visible.)
I did some experiments and I add some empty collumns and that helped so I assume it is something connected with how JScrollPane gets the width of the table it should display but I could not figure out how can I change that. I was trying to call table_.setPreferredScrollableViewportSize(new Dimension()); with Dimentsion set to something really big but it did not help.
Second issue is that when I click on a cell that is placed closer to the right edge then the next cell is being selected. The further the cell is from the left edge the further cell to its right is being selected. I can't see selection when I click on the cell from last collumn.
If there is no easy answer maybe someone knows some open source alternative to display data in table with merging capabilities. I found only commercial ones which cost a lot of money.