• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can i refresh a scrollpane

 
Smilidon Sapiens
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a List, a ScrollPane, and images. If you select something in the List the image in the ScrollPane refreshes, but not the ScrollPane. The size of the images change too, but no scrollbars will be displayed. I have SCROLLBARS_AS_NEEDED.
I overwrite getPreferredSize() of my panel with the picture. getPrefferdSize() returns the size of my image.
Here is the sourcecode of my panel in my ScollPane
<code>

public class panel extends Panel
{
private Image I;
public panel(String str)
{
I = loadPic(str);
}
public panel()
{
I = loadPic("http://www...pic.jpg");
}
public Dimension getPreferredSize()
{
return new Dimension(I.getWidth(this), I.getHeight(this));
}
public void paint(Graphics g)
{
g.drawImage(I, (max_picx-I.getWidth(this))/2, (max_picy-I.getHeight(this))/2, this);
}
public Image getImage()
{
return(I);
}
public void setImage(String str)
{
I = loadPic(str);
repaint();
}
public Image loadPic(String pic_str)
{
Image img;
MediaTracker tracker;
try
{
img = Toolkit.getDefaultToolkit().getImage(new URL(pic_str));
}catch (Exception e)
{
img = Toolkit.getDefaultToolkit().getImage("http://www...default.jpg");
}
tracker = new MediaTracker(this);
tracker.addImage(img, 0);
try
{
tracker.waitForAll();
}
catch (InterruptedException ce)
{
}
return img;
}
}
</code>
Why I can't see the scrollbars if the image is bigger than the image before?
[This message has been edited by Brain Tenner (edited May 18, 2001).]
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Brian,
I am not exactly sure why, but I would start with the concept that the ScrollPane performs the layout once when its' child is added. To get the scrollbars to appear, you might need to force it to layout the child again with a call to doLayout()?
Regards,
Manfred.
 
Smilidon Sapiens
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, I'm very happy.
ScrollPane.doLayout(); works fine!
Thanks
 
Li Shangqiang
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brain Tenner,
Can you give the well code? It can help me very much!
Thanks!
 
GShankar B
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this panel is set as viewportView for scrollpane, then this panel needs to be resized
Try :
panel.setPreferredSize(image.getWidth(), image.getHeight());
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!