How do I make the last column in a JavaFX TableView take the remaining space.
I have tried table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); but this makes the column sizes equal. I want only the last column to grow when the window width increases.
If you want all the columns in your tableview to fill up the window space available to the tableview AND be dynamically resized to adjust to changing the size of the window, then you need to bind the column properties to the tableview's width.
For example, say I have 5 columns in a tableview. I want them to always be a fixed percentage of the available width (so that when the window is resized, the proportions of the columns remain constant). You can easily form your own column sizing rules using the same property binding idiom (eg. I want the last column to take all the remaining space).
In the initialize() method of the controller that has my TableView control, I could do the following:
void initialize() {
// Initialize your logic here: all #FXML variables will have been injected
:
:
// TableView column control variables are prefixed with "tco"
tcoLast.setCellValueFactory(new PropertyValueFactory<Client.Expand, String>("lastName"));
tcoFirst.setCellValueFactory(new PropertyValueFactory<Client.Expand, String>("firstName"));
tcoDoB.setCellValueFactory(new PropertyValueFactory<Client.Expand, Integer>("doB"));
tcoMRN.setCellValueFactory(new PropertyValueFactory<Client.Expand, String>("defMRN"));
tcoGen.setCellValueFactory(new PropertyValueFactory<Client.Expand, String>("gender"));
// Cell factories for rendering certain columns in the TableView
tcoLast.setCellFactory(new ClientNameTableCellFactory());
tcoFirst.setCellFactory(new ClientNameTableCellFactory());
tcoDoB.setCellFactory(new ClientDoBTableCellFactory());
// Set fixed column widths that resize automatically
// Values are weighted to be a fraction of a total of 41 (arbitrary)
tcoLast.prefWidthProperty().bind(tbvMatches.widthProperty().multiply(11.0/41.0));
tcoFirst.prefWidthProperty().bind(tbvMatches.widthProperty().multiply(11.0/41.0));
tcoDoB.prefWidthProperty().bind(tbvMatches.widthProperty().multiply(8.0/41.0));
tcoMRN.prefWidthProperty().bind(tbvMatches.widthProperty().multiply(8.0/41.0));
tcoGen.prefWidthProperty().bind(tbvMatches.widthProperty().multiply(2.0/41.0));
:
:
}
Related
Two questions:
1.) How do I put a min limit on column resize in JTable?
2.) How do I stop data from showing a "..." on column resize when data can't fit into cell?
//Minimum width 100 for first column
table.getColumnModel().getColumn(0).setMinWidth(100);
About the ..., I am not sure you can do anything but keeping the minimum width of the cell according to its value.
I have a simple grid. Two columns with a variable amount of rows. I want to make it so i have a header row with an arrow that can collapse and show the whole grid. So when I bring up the app, only the header row is visible with an arrow, and I can click to expand/collapse to show the rest of the grid.
A TreeGrid seems like overkill since I don’t need any hierarchical structure, just the ability to collapse/expand one row. I exclusively use IE and I’ve read that Drawyer doesnt work with IE 8 and above. I return a list of the objects and the object just has two string variables.
Any help with this? I am new to Vaadin 8.
Set grid height (workaround)
As a workaround, you could set the height to be approximately the number of pixels you expect to be the height of the header.
See the Sampler demo. Click the gear icon at top to expose properties of the example Grid object. The last property shown is "Size (W x H)". Change 100% to 100px to see the effect.
Grid height set to 100%
Grid height set to 100px
You can also hide the footer (see checkbox in that property list).
I don't think this can be done with plain Vaadin. But I recommend the following simpler approach:
Initially call grid.setHeightByRows(1.5) (javadoc). This will show exactly one row and a half to indicate more data is available. A scrollbar will appear, too.
Make a new column within the grid that has a button or add a button below the grid that - when clicked - calls setHeightByRows with the number of elements in the grid and hides the button. This will show all rows.
My requirement is displaying a varying number of Rows in a tabelView, where each row contains a label column and a second colum,n with either a textBox, comboBox, richtext or datePicker.
The user may enter some of the values and start a search via a button, displaying the result sint he bottom half of the splitPane.
This table is displayed in a vertical splitPane like this:
Name | txtName
date | datepickerDate
gender | cmbGender
----------------------------
Results will be shown here
The number of rows of the top-table may vary from 1 to 20+.
I have fixed the maximum splitPane size to be 50%-50% distributed, if the table requires more space than 50% of the window, the user needs to scroll.
What i need is a possibility to, at runtime, know how much space the table actually needs. this is dependent on font-size and contents of the cells (eg.: a richtext-control is slightly larger than a textbox) is there a way to know the actuall space the tableview is going to need?
All question i found here relate to fitting the tableview to the window-size, i need it the other way round, i need to place the SplitPane separator where the table ends
Thanks in advance,
BillDoor
After i added a MenuButton I can not I can not get correct size
The tableView after load looks like this
How can i set each column's width to equal inner content width of that column ? OR Right blank space should be distributed in a balanced way
I can not do them both
tableColumns[i].setMinWidth(tableColumns[i].minWidthProperty().get() + 50);//does not work
tableView.columnResizePolicyProperty().set(...)//not work too
I have a Swing JTable. It is large and users can scroll up and down to see the row of data they want to work on. When the user stops scrolling, I want to know the row number of the JTable that is the first visible row that the user can see. I want to use this to scroll back to this position in the table after the user is through additional operations (I know how to do the scrolling piece - its getting the first visible row that has me stumped).
You first need to find out which part of the table is visible and then map the visual coordinates to the underlying row:
JViewport viewport = scrollPane.getViewport();
Point p = viewport.getViewPosition();
int rowIndex = table.rowAtPoint(p);
In addition to that you might want to experiment with offsets to p (such as, e.g., offsetting it by half a row height etc.) depending on the behavior you want to achieve when the first visible row is only partly visible.