Why all images shrink into a small dot in FlowLayout?

Dear friends:

When I use BorderLayout and GridLayout in JPanel, all images and JLabel are shown up properly,

but when I change Layout to FlowLayout, JLabel still display, but all

all images shrink into a small dot in FlowLayout, what is wrong?

Why all images shrink into a small dot in FlowLayout?

Thanks

sunny

[353 byte] By [sunnymanmana] at [2007-11-26 21:11:19]
# 1

Never seen it happen. FlowLayout respects the size of each component. As the frame width is decreased, some labels will not be painted, but they don't shrink in size.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-10 2:48:47 > top of Java-index,Desktop,Core GUI APIs...
# 2

add the following:

Dimension dim = new Dimension(100,100); // insert whatever size you want

Then on your JLabel, do the following:

yourLabel.setMaximumSize(dim);

yourLabel.setMinimumSize(dim);

yourLabel.setPreferredSize(dim);

It is probarbly overkill to set all those, but I guess its better to be save than sorry.

alienchilda at 2007-7-10 2:48:47 > top of Java-index,Desktop,Core GUI APIs...
# 3

Thanks a lot,

but still fails, see code below

JPanel jpanel = new JPanel(new GridLayout(4, 3));

//JPanel jpanel = new JPanel(new FlowLayout());

Dimension dim = new Dimension(100,100);

jpanel.setPreferredSize(new Dimension(500,500));

pic1 = new getImage(createImageIcon("dog.jpg").getImage());

JLabell1 = new JLabel();

// l1.setPreferredSize(new Dimension(60,60));

l1.setMaximumSize(dim);

l1.add(pic1);

l1.setVisible(true);

//jpanel.add(l1.getComponent(0));

jpanel.add(l1);

add(jpanel);

any new idea?

Message was edited by:

sunnymanman

sunnymanmana at 2007-7-10 2:48:48 > top of Java-index,Desktop,Core GUI APIs...
# 4

> It is probarbly overkill to set all those, but I guess its better to be save than sorry.

No, it is not better to be safe than sorry. It is better to understand how LayoutManagers work. Adding unnecessary code will cause confusion as people maintaining the code will wonder why the code is there.

There is not need to invoke any of the sizing methods. The preferred size of the lable will be the size of the image. So if the image is loaded correctly there is nothing that has to be done.

> any new idea?

Your where given an idea. Post your SSCCE. No SSCCE. The code you posted is incomplete. We have no idea what your getImage(...) method does or for that matter why you even have a getImage() method. If you would read the Swing tutorial on "Using Labels" or "Using Icons" then you would find working examples.

camickra at 2007-7-10 2:48:48 > top of Java-index,Desktop,Core GUI APIs...