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);
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.
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.
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).
I have a JTable inside of a JScrollPane. I want to get the columns to stay fixed when I resize it. The rows stay the same size, and there is a scrollbar to move up and down. I can't get the scrollbar to work the same way on the vertical though.
Here is a picture of my project, where the y axis of Duke is perfectly normal, and has a scrollbar to scroll to the bottom of the image, the horizontal part is clearly messed up, and should not have expanded that far.
Also, if the frame was made smaller horizontally, there should be a scrollbar just like the vertical.
So my question basically ends up like this; How do you fix the size of a JTable to not resize within the JScrollPane, and then if it's too large for it, display scroll bars.
Btw, Each cell has an image, making up the big image.
Set the table's auto resize mode to "off"
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Take a look at JTable#setAutoResizeMode for more details.
Update
I should mention, this will mean you will become responsible for determine the size of each column.
Take a look at How to use tables and Setting and Changing Column Widths
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%)".