In Grid component when I try to resize frozen column too much it goes out of the grid and there is no way I can resize it back to its initial positionThis is an example from Vaadin sampler.
Is there any way I can prevent frozen columns from extending out of the grid?
I tried to call setMaximumWidth() on frozen columns however this seems to not work on columns that are being resized.
Sounds like the manual column resizing is not respecting the maximum width, so it's a bug in Grid.
Related
For my Java Swing app I want to display a grid of items, fixed to two columns, and for the elements (grid items), I want to use fixed height, and if due to its height they don't fit, place a vertical scrollbar.
For anyone who knows a bit about Android development, is more or less what GridView does perfectly.
So, I'm trying to find a way to do that. I tried with a JPanel with GridLayout inside a JScrollPane, but in this case the elements get too much width and I also need a horizontal scrollbar, which definitely is not what I want.
So, what do you suggest?
Thank you.
After starting a JPanel using GridLayout(4,4) i insert a JLabel (and attach an imageicon to it) inside every grid cell with size of (150,150).
when i resize the JLabel to size (100,100) the image get cropped (which is perfectly fine by me), but i get a wierd looking grid (imaged added at the end).
if this helps: i dont actually resize the window, i just need to make sure the the size of the JLabel is set to (100,100) always, no metter what is the original image size.
before:
http://postimg.org/image/iolyeb8e7/
after:
http://postimg.org/image/5j6g87ein/
thanks
Unfortunately you did not say what you expect the grid to look like. I assume you don't want the cells to be so far apart from each other.
The GridLayout documentation states that...
The container is divided into equal-sized rectangles, and one component is placed in each rectangle.
If you shrink the size of each JLabel (i.e. the components in each of those rectangles) you just do that. You shrink the size of the component, not that of the rectangle. The grid does not care if the component is to small to fill the whole rectangle. At the moment you add the component to the grid1, the grid tries to set the components size to best fit the available space. But if you later change the labels size, the grid does not care.
What you probably want is to change the size of the whole grid: If you set the grids size to 400 by 400 it should evenly divide it to all 4 rows and 4 columns, so you get rectangles of size 100 by 100. All labels should automatically be sized accordingly.
1 Probably it is not exactly while adding the labels but while validating the container, but I don't know all the internal details about how and when layouts do there magic.
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.
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.
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