Problems with resizable container
Hi,
I have a resizable JPanel with cubes inside it.
The problem is when I resize the JPanel the cubes inside it gets resized only after I move the borders of the JPanel ~14 pixels...
The problem is in the X axis...
The Y axis "jumps" every ~5 pixels...
I need content of the JPanel also to resize every 1 pixel (so it would be on the borders of the JPanel)...
Any Ideas?
[413 byte] By [
Xtrima] at [2007-11-26 15:44:31]

Without having seen your code I guess it has something to do with
integer division, i.e. if a single cube takes up 1/20th of the width of your
panel, your panel has to grow at least 20 pixels in order to make the
width of your cube change one single pixel. Just a guess.
kind regards,
Jos
Hi,
Thats what I thought...but there has got to be a way...
I even tried refreshing the content while re-sizing...no good.
If it was a picture then it wouldn't be a problem....
I guess that the only solution is NOT to use gridLayout and do it all manually...
unless you have other suggestions....?
OR maybe you know of a way to convert a JPanel to a PIC?
> Thats what I thought...but there has got to be a way...
> I even tried refreshing the content while re-sizing...no good.
> If it was a picture then it wouldn't be a problem....
>
> I guess that the only solution is NOT to use gridLayout and do it all
> manually...
>
> unless you have other suggestions....?
Yep, don't do it manually, it'll be a mess. When you draw your 'cubes'
(or whatever) you use a Graphics object. Have you considered using
a Graphics2D object instead? Don't worry, you can simply downcast
your Graphics object to a Graphics2D object because the first one
actually *is* the latter.
A Graphics2D object allows you to use world coordinates instead of
device (pixel) coordinates, e.g. you simply specify that your JPanel is
WxH points wide and high and use that dimension for the drawing stuff
no matter the actual size of the JPanel measured in pixels.
kind regards,
Jos
> I guess that the only solution is NOT to use gridLayout
Well that would explain the behaviour. It would have been nice if that information was included in the original question. Thats why I always ask for a SSCCE, since you never no what information is importan or not.
All components in a GridLayout have the same size. So if you have a Grid with 10 component that is 400 pixels wide each component will be 40 pixels wide. As suggested above the size of each component will only be adjusted when you incread the width by 10 or more (since you have 10 components in each row).
Doing it manually would also be a pain. If you increase the width by 1 pixel you would only be able to increase the size of one component. Then if you increase it by one pixel again you can only change one component, so do you change the first one again or the second. So now you need an algorithm to determine which component gets the extra space.
> I need content of the JPanel also to resize every 1 pixel (so it would be on the borders of the JPanel)...
Don't know exactly what your layout is like, but maybe you could center the panel in the frame. That way as you change the size the "border" will change on both sides and it may not look as bad.
You can try using a BoxLayout. Components will grow as the size is increased but I think you might have problems with the first components always growing first.
