Calculating dimensions of a cell in a JTable - java

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.

Related

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.

JTable, How to set different side borders

In my project i need to draw a facility plan.
I need to draw table made from squares and i tought i can make it with JTable component.
But there is one more thing i need:
I need to set different borders every cell but also i need to draw border to different sides of cells.
Here are my questions:
Is there any way to process every cell different?
Is there any component to do this?
Or is there any options to do, without jtable?
thank you so much.
regards
Check out Table Row Rendering. It gives an example of how you might customize the Border for all cells in a row. You should be able to customize for your exact requirement.

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.

Can we set/adjust size of JTable column as per the size of GUI Component?

In my project,i need to adjust the sizes of columns in JTable as per the sizes of GUI Components such as JComboBox and JTextField. Can we adjust the size of column as per the size of GUI Component ?
but the size of column seems to be in pixels
What is the problem with that? The size of Swing components are also in pixels.
See the section from the Swing tutorial on Setting and Changing Column Widths for more information.

GXT grid auto columns width

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

Categories