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.
Related
I want to get the text width in pixels of each tree item from a TreeViewer having 2 columns, so that I can get the maximum sized tree item to fix it as its respective column's width.
I have already tried using pack method, but it doesn't solve my purpose, as it fits column width to content size for the 1st level items, but not from 2nd level onward.
Please suggest any other way to autofit the column width to content size in JFace TreeViewer in Java.
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 use font size to zoom data view when I increase font the size column header height increase in the right way but when reset font size column header height don't decreased how can I fix that , I am use java fx u40
Check if it is not just a refresh problem.
One way of checking this is:
yourTable.getColumns().get(0).setVisible(false);
yourTable.getColumns().get(0).setVisible(true);
This is my code
JTable table = new JTable(attributeValues, attributeNamesString);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
for(int z=0;z<table.getColumnCount();z++){
table.getColumnModel().getColumn(z).setMinWidth(100);
table.getColumnModel().getColumn(z).setMaxWidth(100);
table.getColumnModel().getColumn(z).setPreferredWidth(100);
}
Unfortunately, when I run this, I get an additional column on the screen which stretches to the window size. I'm not sure where it's come from or how to fix it.
Are you sure this is caused by the table.getColumnModel().getColumn(z).setPreferredWidth(100); call? I suspect (although I haven't tried it myself) that it is more likely caused by table.getColumnModel().getColumn(z).setMaxWidth(100);, as this sets the columns' maximum width (adding up to 4 x 100px in your case) while the table itself is stretched to more than 4 x 100px.
If you do not want the table itself to be wider than 4 x 100px, can you not set the maximum size of the table as well (http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#setMaximumSize(java.awt.Dimension))?
I am trying to export a table as xlsx using Apache POI XSSF. Table has 5 columns.
First row has title block merging 5 columns. In the second row, 5 headings for the table. Remaining rows are data. I want to set width of the column as max width of each heading blocks.
I tried mySheet.autoSizeColumn(colnum) and mySheet.setColumnWidth(columnIndex, width). Problem with AutosizeColumn, it is returning the highest width of the data in all the rows. So If width of some data in table is more, table header width is becoming very large.
And for the second one, setColumnWidth, I need to know width of the header cell so I can set it to the sheet. But how to find the width of a specific cell? Had no luck yet in figuring out how to do it. Any idea on how to that?
I would suggest simple solution that I have used.
Use a condition and after writing the 2nd row, i.e. the heading row, use AutosizeColumn() it will change the cell width according to the header width and then the width will remain as it is.