Get columns to stretch entire width of the table - java

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.

Related

JTable setPreferredWidth causing an extra column

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))?

Column dividers in JTable or JXTable

I Have a JTable (or a JXTable to be more precise) with 3 sections of grouped columns I want to divide.
I used to have 3 tables which i programmatically linked (the scrollbar position, the sorting, the selection). I used a lot of code to get this linked, and I want to get rid of this.
Now I Am switching to 1 JXTable, because there are some things a lot nicer in this table class.
I found some (not very satisfying) solutions to almost the same problem.
Maybe some one has a good suggestion for me.
Option 1: an empty column as a divider (another color, like gray) and programatically hop over this empty column when using the arrows or tab keys.
option 2: setting the margin for just 1 side of 1 column to a larger size, so it seems like a divider. Untill now I have only found out how to set the margins for all columns
option 3: getting back to 3 seperate tables again (especially to get the tables sorted in the same way is a lot of work, because I do not want to repeat the columns in the seperate sections). This means I have to rewrite my table sorter, sorting on a non-visible column.
any suggestion is welcome (also if it's none of the three given options)
I've made something that looks somewhat like what you're going for by overriding the cell renderer on the 3rd column to have a thick right border and no other borders. You could do the same within the table column header to have the border extend up through there. It's clearly placing the border within the cell but this may be sufficient for you.
{
....
table.getColumnModel().getColumn(2).setCellRenderer(
new ThickRightBorderCellRenderer());
....
}
private static class ThickRightBorderCellRenderer
extends DefaultTableCellRenderer {
#Override
public Border getBorder() {
return BorderFactory.createMatteBorder(0, 0, 0, 3, Color.BLACK);
}
}

How to mix fixed and relative columns width in gwt celltable

I need to create a celltable with 100% width and I need a relative width column and another two with fixed width.
I am doing it in this way:
table.setWidth("100%", true);
table.setColumnWidth(checkBoxColumn, 50, Unit.PX);
table.setColumnWidth(nameColumn, 35.0, Unit.PCT);
table.setColumnWidth(emailColumn, 65.0, Unit.PCT);
as says in http://code.google.com/webtoolkit/doc/latest/DevGuideUiCellTable.html
In FF it runs ok, but in Google Chrome but I can't get it working.
This is what I am getting http://www.under-code.com/cap-celltable.png
How can I fix this? Is there anything that I am doing wrong?
From the screenshot of your DOM, I notice you have a table inside of a table. The upper most table having no width, and the inner most table having width 100%. I believe the upper most table having no width is what is giving you trouble here.
By any chance are you using a VerticalPanel to layout your CellTable? It's underlying implementation is a table which can cause this sort of wonkiness.
If so, you can try:
1: Using a FlowPanel, SimplePanel, or HTMLPanel instead. Their underlying implementations are divs, which as a block level element will expand to fill the entire width of their parent.
2: Apply width=100% to your VerticalPanel

width of the JTable is constant and so cannot view the graph properly

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)

How to scale images in an SWT TableItem?

I have been struggling to get the images displayed in an SWT TableItem to scale. I have a listener which scales the fonts correctly, and I have confirmed that the images being set into the TableItem are correctly scaled. I know that the scaled images are being successfully set into the TableItem, because I can even change what image gets displayed. But the new image is always displayed at the original scale.
I have read in SWT: The Standard Widget Toolkit, Volume 1 where the authors state:
The First Image Defines the Size of
All Images in the Control
Due to a Windows limitation, just like
ToolBar, TabFolder, and Tree, Table
scales the images it displays to be
the size of the first image inserted
into the control.
The behaviour I'm seeing is the most extreme case suggested by this quote -- images in the table seem to be being scaled, not the the size of the first image in the table, but to the size of the first image ever to have been in the table. Can anyone confirm or refute this? Does anyone have any more detailed information about the behaviour of images in TableItems? Is this restriction really the show-stopper it seems to be?
And in particular, if I go down the path of custom drawing table items (Custom Drawing Table and Tree Items), am I likely to bump into any further showstoppers?
(You'll note what a good job I'm doing of gritting my teeth and not giving way to rage at having to deal with Windows stupidity even when using a supposedly cross-platform development environment!)
I can confirm this in my experience on Windows.
I propose one of two solutions:
Use custom table drawing as per the link you mentioned. It's a little annoying but not more than 2 hours of work I'd say to learn and implement it.
Use an alternative SWT table control e.g. Nebula Grid or KTable which do not share the same platform limitations of Table on Windows
Edit: in response to "And in particular, if I go down the path of custom drawing table items (Custom Drawing Table and Tree Items), am I likely to bump into any further showstoppers?"
The only issue I found with custom drawing is that it's best to know ahead of time what the maximum row height will be, otherwise there will be jumping when Table has to increase the row height and therefore scroll items a bit while it readjusts

Categories

Resources