Skip to main content

Resizing a panel

2 replies [Last post]
shacoshe
Offline
Joined: 2006-04-18

hello
i have a JPanel with a Borderlayout
at the center of the panel there is a label with image
at the south of the panel there is a label with text

when i use the timing framework resize the JPanel
the image in the center will not starch to the new size

here is my code :
public class CastPanel extends JPanel{
public CastPanel(){
...
....
...
...//Request focus using mouse event
JLabel labImg = new JLabel(img);
JLabel labText = new JLabel("this is a text");

addFocusListener(new FocusHandler ());
setLayout(new Borderlayout());
add(labImg ,Borderlayout.CENTER);
add(labText ,Borderlayout.SOUTH);
}

}

private class FocusHandler implements FocusListener{
public void focusGained(FocusEvent e){
JComponent com = (JComponent)e.getSource();

int jump = 10;
Rectangle bounds = com.getBounds();
Rectangle bountsNew = new Rectangle(bounds.x - jump ,bounds.y - jump ,bounds.width + (jump*2) ,bounds.height + (jump*2));
KeyValues vals = KeyValues.create(bounds, bountsNew);
KeyTimes times = new KeyTimes(0.0f, 1.0f);
KeyFrames frames = new KeyFrames(vals, times);

Animator animator = PropertySetter.createAnimator(200 ,com ,"bounds" ,frames);
animator.start();
}

public void focusLost(FocusEvent e){
JComponent com = (JComponent)e.getSource();

int jump = 10;
Rectangle bounds = com.getBounds();
Rectangle bountsNew = new Rectangle(bounds.x + jump ,bounds.y + jump ,bounds.width - (jump*2) ,bounds.height - (jump*2));
KeyValues vals = KeyValues.create(bounds, bountsNew);
KeyTimes times = new KeyTimes(0.0f, 1.0f);
KeyFrames frames = new KeyFrames(vals, times);

Animator animator = PropertySetter.createAnimator(200 ,com ,"bounds" ,frames);
animator.start();

}
}

thank u please help

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shacoshe
Offline
Joined: 2006-04-18

where should i call the com.doLayout() in each "resolution"

please helpppp

shacoshe
Offline
Joined: 2006-04-18

i solved the problem

i added a componentListener to the panel that i use to resize
and called to the dolayout method

private class ComponentHandler extends ComponentAdapter {
public void componentResized(ComponentEvent e){
doLayout();
}
}