Skip to main content

changing JXImageView height

No replies
wwiktorr
Offline
Joined: 2006-05-05

In first words I want to underline that this isn't JXImageView problem, but in Swing general.

What I want to do?

I want to scale an image and than just change preferredSize's height. All I need to know to compute height is my parent's (container's) width.

How am I doing it now?

I started with overriding method getPreferredSize(). I asked my parent getParent().getSize() to get info about his weight, but in first few invocations of getPreferredSize() the getParent().getSize().width is 0. This is a problem, because not always (sometimes yes) component is not painted well.

Then I started to override the paint() method like that:

if (recentWidth != getSize().width) {
// computations
// setting prefered size
// revalidate()
}

super.paint(g);

It is working better, but not always.

Do You know how to deal with this kind of problem?

Thanks in advance :)