• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how can i refresh a scrollpane

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot, I'm very happy.
ScrollPane.doLayout(); works fine!
Thanks
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brain Tenner,
Can you give the well code? It can help me very much!
Thanks!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
reply
    Bookmark Topic Watch Topic
  • New Topic