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.
Related
Everywhere I look for help with GridBagLayout only helps with GridBagConstraints. I understand that part completely, it's the methods inside GridBagLayout that confuse me.
So I realized that the fields columnWidths and rowHeights are for overriding GridBagLayout's cell widths and heights, and are null until set by user. (I have implemented those fields in my program below) So how do I get the ACTUAL width and height of the cell?
I'm basically trying to override the paint method of the container in order to draw a grid that show where each cell begins and ends (where gridwidth and gridheight is irrelevant). The one thing that looks applicable is getLayoutInfo(Container parent, int sizeflag), but GridBagLayoutInfo has no methods or fields, and I have no idea what it means by sizeflag.
EDIT:
This is basically the grid I would like to draw, but of course I want to make sure it would work on any container where gridlayout is the layout manager. These are the actual gridx and gridy coordinates highlighted in red. I just don't know how to get the values I need to the paint method.
GridBagLayout has a method getLayoutDimensions() which returns array of two arrays. First array is column widths and second array is row heights. This method considers insets set in GridBagConstrains of each cell to be part of the cell.
I know this question is stale but I ran into simmilar problem recently and found it while searching for solution.
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);
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.
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).
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.