GXT grid auto columns width - java

I have a GXT Grid and want the columns in it to fit to the screen. here what my grid looks like now:
It looks so because I've set the concrete values for widths of the columns, which fits to my screen. And I'd like columns automatically fit to the grid's width

The Javadoc is pretty clear about this :
Grids support several ways to manage column widths:
The most basic approach is to simply give pixel widths to each column. Columns widths will match the specified values.
A column can be identified as an auto-expand column. As the width of the grid changes, or columns are resized, the specified column's width is adjusted so that the column fills the available width with no horizontal scrolling. See GridView.setAutoExpandColumn(ColumnConfig).
The grid can resize columns based on relative weights, determined by the pixel width assigned to each column. As the width of the grid or columns change, the weight is used to allocate the available space. Use GridView.setAutoFill(boolean) or GridView.setForceFit(boolean) to enable this feature:
With auto fill, the calculations are run when the grid is created (or reconfigured). After the grid is rendered, the column widths will not be adjusted when the available width changes.
With force fit the width calculations are run every time there are changes to the available width or column sizes.
To prevent a column from participating in auto fill or force fit, use ColumnConfig.setFixed(boolean).

Related

Vaadin 6 . Set table heigth to fit context

I have a Table in my project inside a Panel inside a VerticalLayout and I need to set table height to fit the context. If I set
table.setsizeFull() ;
table.setPageLength(0);
then table height is much smaller than necessary and there are vertical scrollbar.
I tried to do like this:
table.setPageLength(table.getItemIds().size() + 1);
table.requestRepaint();
but in this case there are a lot of space under the table. I tried to set setSizeFull() for all elements but this has no effect.
When I tried this:
table.setPageLength(table.getItemIds().size());
table.requestRepaint();
effect was the same, as in first case (smaller height and vertical scrollbar).
How can I set table heigth to fit context?
Fixed by this:
table.setWidth(100, UNITS_PERCENTAGE);
table.setHeight(SIZE_UNDEFINED, 0);
table.setPageLength(0);

How to set column width of Jtable equal to a checkbox

Below is the picture.
I am using following code but it's not setting width to size of checkbox
TableColumn column = null;
column = table.getColumnModel().getColumn(0);
column.setPreferredWidth(1);
I want to remove spaces around checkbox
The TableColumn has 3 widths, minimum, preferred and maximum.
Setting the width to 1 makes no sense since the checkbox won't paint in 1 pixel, so I would guess the minimum value is being used. Also, depending on the auto resize property the value could be overridden to make sure the column widths will fill the table view.
Try setting the minimum and preferred sizes to the same (reasonable) value.
A better approach is to not guess at the width since it could change for different LAF's. Instead you can use the renderer to determine the appropriate width for the column. See Table Column Adjuster for basic example code you can use and a more complex class that provides a complete solution.

Editing the height of a specific row in GridLayout Java

I want to edit the height of a single row in a JFrame with a GridLayout. Is there any way to do this or must the height of every row be constant?
Is there any way to do this..
Not with a single GridLayout.
..or must the height of every row be constant?
Yes, every row in a single GridLayout is the same height, and every cell is the same width.
Provide ASCII art (or an image with a simple drawing) of the GUI as it should appear in smallest size and (if resizable) with extra width/height.

Calculating dimensions of a cell in a JTable

How can I calculate the dimenstions of the cell in JTable containing various components to calculate the height of table dynamically.
For example, I have a table containing multiple checkboxes in the 3rd column and various components in other columns. When new components are added to the cell, then the height and width of the whole table should change dynamically.
Thanks in advance.
You might be able to leverage the approach shown here, which invokes setRowHeight() to accommodate the maximal height of each column's renderer.

Fixed percentage based grid with MiGLayout

I am trying to create a grid with MiGLayout that is enforced on its children. This means that if I insert a child into grid position (1,1) and the grid's size is [10%!] that this child must NOT be bigger and overlap other cells. The child must be shrunk to fit the Grid cell.
This is what I have so far:
new MigPane("", "[5%!][20%!][5%!][65%!][5%!]", "[45%!][50%!][5%!]");
Now, I insert a big component (a picture that I have no control over) in Grid 1,1, like this:
migPane.add(myImageView, "cell 1 1, width 100%!");
However, that does not seem to restrict the ImageView at all.
How do I tell MiGLayout that I want "myImageView" to be put in grid 1,1 and size it to fit? Is there a "fit" keyword? :)
Note that specifying anything with pixels/points/mm/cm/inches is NOT what I want. My app always runs full-screen and must scale seamlessly (it is not a traditional form app, it is a video system using JavaFX).
It looks like percentages are supported, according to the docs:
Overrides the default size of the component that is set by the UI
delegate or by the developer explicitly on the component. The size is
specified as a BoundSize. See the Common Argument Types section above
for an explanation. Note that expressions is supported and you can for
instance set the size for a component with "width pref+10px" to make
it 10 pixels larger than normal or "width max(100, 10%)" to make it
10% of the container's width, but a maximum of 100 pixels.
Maybe try something like: "width max(100%, 100%)".

Categories