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))?
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.
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 want to create a jtable where each cell should be the size of a single character, without any separation between adjacent characters (i.e adjacent columns). There are no borders between columns so the visualization of a sequence of columns is indistinguible of a jLabel. I have tried many things like making the width of a column as small as possible until each cell is displayed as ... meaning there is no space to print the character. So say I want to have 5 consecutive cells to print the name Alice. What I have achieved so far is a table with this aspect
A l i c e
If I make the column width smaller it shows
... ... ... ... ...
And what I want is:
Alice
Thanks!!
Alvaro
What is the point of doing something like this? This will only work for a single row.
What if you have two rows:
Alice
SWITCH
The minimum width of the column will be controlled by the "W" in the second row, which means you will always have extra space around the "l" in Alice.
Why don't you just use a JPanel with a BoxLayout and then add multiple JLabels to the panel?
Anyway, if you feel you still need a JTable then you can check out the Table Column Adjuster which attempts to fit the text. The basic code would be:
TableColumnAdjuster tca = new TableColumnAdjuster(table, 0);
tca.setColumnHeaderIncluded( false );
tca.adjustColumns();
Also, make sure you use JTable.setIntercellSpacing(...) to set the Dimension to 0.
I'm working in Java using the Vaadin framework.
I have a table with 14 columns. My problem is that that there's a small gap to the right of the last column, like the beginning of a new column that shouldn't be there..
The image shows the problem:
I've tried solving it with using column expand ratio on the last column, but this makes it abnormally big..
Do any of you know of a property you can use, CSS or Java, that makes the columns stretch over the entire width of the table without causing large column disproportion?
This is known issue, it was closed already Ticket #6677
If you set your table to fullsize that should probably close the "gap".
YourTable.setSizeFull();
I gues you ahve your table in a layout. Set this layout margin to false and also remove spacing.
This is a continuation of the problem here jtable to image conversion not happening properly, I have implemented the answers mentioned in the previous link.
I now see that the width of the table is always constant at 300, this is okay when the table height is small, for tables which are very long the tables become really thin and the image of this cannot be used for rendering at all.
The number of columns in most tables are constant to 4.
Please do let me know if there is anything that I can try here.
Set the size of the scroll pane instead.
pane.getViewport().setViewSize(300, 700)