I have a custom table class which extends JTable. I want a column to be visible/invisible based on a checkbox. I have an actionlistener on the checkbox that changes the max, min, and preferred width of the column in action.
When the checkbox is NOT selected, then I set the min/max/preferred width to 0. When it is selected, I set the min/max/preferred width to a normal size.
My issue is, when I click to select the checkbox, the table does not change. I do not see the column. However, when I resize the application or any of table columns, the table gets updated and my new column is now visible properly.
I tried calling "table.repaint()", and that did not do anything. My ideal approach now would be to just figure out what gets called during an application/column resize that causes the update, and just call it from my listener.
I have an actionlistener on the checkbox that changes the max, min, and preferred width of the column in action.
Don't play with the column size. The column will still be part of the table and will confuse the user as they tab from column to column since the cursor will disappear on the minimized column.
Instead you want to remove the column from the view of the table. So you need to remove a TableColumn from the TableColumnModel of the table.
Check out the Table Column Manager. This allows you to hide/show columns as required.
Related
I have two JTable components, I want that if i click on any row of first table then, the elements having same ID in table 2 also, changes their background color.
I searched these while R&D
Java Code Examples for javax.swing.JTable.prepareRenderer()
Change background color of one cell in JTable
Add a ListSelectionListener to the first table. It will generate an event whenever the selection of a row is changed
When the event is generated you clear the selection of the second table and then iterate through all the rows of the table finding rows with the same id. Then you can invoke the changeSelection(...) method on that table.
I have a JTable that when clicking on the row expands it and filters all other rows in the table. When the user clicks on this expanded row again it returns to its normal size and the filter shows all the table again. All this works fine but when returning from the view of a single expanded row to the whole table I would like to set the scroll pane vertical scroll bar value to that one which is the position of the row that have been expanded. I correctly compute this value and try to set it with
scrollPane.getVerticalScrollBar().setValue(value);
but as I have found with scrollPane.getVerticalScrollBar().getMaximum() the scroll bar doesn't update its values after sorter.setRowFilter(filter); invocation. getMaximum() returns the height of that single row that have been expanded and for that reason scroll bar fails to set the updated value (that is typically much greater). This is the code:
// after this call the table shows all its rows again
sorter.setRowFilter(filter);
System.out.println("maximum=" + scrollPane.getVerticalScrollBar().getMaximum());
// shows old value when the table has consisted from a single expanded row
scrollPane.getVerticalScrollBar().setValue(value); // fails
Can anyone tell me how to let the scroll bar to know that the view of JScrollPane has changed so it can correctly set its maximum value? (though the scroll bar itself seems to be ok and looks like it has look properly scrolling all table). I have tried to call revalidate and updateUI methods on the JTable but it doesn't help.
scrollPane.getVerticalScrollBar().setValue(value);
Try wrapping the above code in a SwingUtilities.invokeLater(). This will add the code to the end of the event queue.
You need to revalidate the JScrollPane, but only after you invalidate the JTable. Thus, something like
sorter.setRowFilter(filter);
sorter.invalidate();
// shows old value when the table has consisted from a single expanded row
scrollPane.revalidate();
I have an Eclipse SWT table. It contains multiple rows (with row headers) and multiple columns (with column headers). On click on a column header I want to deselect all rows and highlight only the column's header (or all cells of this column). Is that possible?
I already registered a listener for the column header's selection and am able to set the selection to the given column, but then it also always selects the first row automatically. I tried with SWT.FULL_SELECTION and SWT.SINGLE as the style of my table, but it only changes the way how the row is highlighted, but I want only to highlight the column's header (or optionally all cells of this column) and no rows.
Is it possible? Did anyone have the same problem?
I ran into the same problem and I'm afraid you can't do that in SWT.
I solved by imitating the selection of a column; I colored the cells as if they were selected, and dropped the "real" selection.
You should extend your own TableViewer and override the getSelection() method to reflect that you now also have this imitated kind of selection.
(And from a UX perspective, you should make sure that a copy command (i.e. Ctrl+C) behaves as users expect it.)
I am using smartGwt 4.0, ListGrid allows us to add multiple columns with auto generated checkbox selection. I am using below property to get checkboxs for each record in the grid,
listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
I have many columns in the ListGrid so it comes with horizontal scrollbar, when i try to scroll to the right side, the selection checkbox column gets scrolled and after verifying mutil column values user has to scroll all the way left to select the record, this is bit annoying, is there a way to freez the checkbox column in ListGrid...?
yes you can do it using ListGridField#setFrozen().
whether this field should be "frozen" for the purposes of horizontal scrolling.
sample code:
listGridField.setFrozen(true);
--EDIT--
Try with ListGrid#freezeField() or other equivalent methods.
For detailed information have a look at FrozenFields
If it doesn't work then add your checkbox column instead of using default checkbox selection appearance and now make it frozen.
I have a JTable such that:
ID #: Name:
0 Entry 0
1 Entry 1
2 Entry 2
When a variable:
private int HighlightEntryID = 2;
is set to an ID #, the JTable should then be able to highlight the corresponding entry.
I have created a Custom Cell Renderer and with the following code:
TableColumn column = CISTable.getColumnModel().getColumn(0);
column.setCellRenderer(new CustomCellRenderer());
I render cells based on the ID # column. My questions are:
It only highlights a specific (row, column) entry. I want to highlight the whole row. How do I highlight other columns in the same row?
When the variable: HighlightEntryID is changed, the JTable doesn't automatically reflect the change. I must refresh the table manually. How do I refresh it automatically?
It only highlights a specific (row, column) entry. I want to highlight the whole row. How do I highlight other columns in the same row?
I like to use Table Row Rendering for this.
When the variable: HighlightEntryID is changed, the JTable doesn't automatically reflect the change. I must refresh the table manually. How do I refresh it automatically?
Invoke the following to force repainting of the entire table:
table.repaint();
You can use setDefaultCellRenderer(Object.class, new CustomCellRenderer()) method of JTable..
And also you should put highlightEntryID variable to your table class..