T
Thomas Richter
Hi folks,
is there a certain rule for making up components when overloading the
"paint" method of a JPanel? I've having here a class that does this:
class ImgPanel extends JPanel {
...
public ImgPanel(Tree t) // no matter what this is right now
{
super(false);
int w,h;
tree = t;
w = tree.getWidth();
h = tree.getHeight();
dim = new Dimension(w,h);
setSize(w,h);
setPreferredSize(dim);
setOpaque(false);
}
public void paintComponent(Graphics g)
{
tree.draw(g,0,0,this);
}
}
Now, everything is fine as long as I add this to the top level content
pane of a JFrame - it's rendered correctly. However, as soon as I add
this into a JScrollPane, trouble begins. The image gets rendered, but
something then erases the image again with the default grey background,
writing on top of my rendered image. I've already tried to set the
JScrollPane to non-opaque, but no go. Any idea what's going on here?
So long,
Thomas
is there a certain rule for making up components when overloading the
"paint" method of a JPanel? I've having here a class that does this:
class ImgPanel extends JPanel {
...
public ImgPanel(Tree t) // no matter what this is right now
{
super(false);
int w,h;
tree = t;
w = tree.getWidth();
h = tree.getHeight();
dim = new Dimension(w,h);
setSize(w,h);
setPreferredSize(dim);
setOpaque(false);
}
public void paintComponent(Graphics g)
{
tree.draw(g,0,0,this);
}
}
Now, everything is fine as long as I add this to the top level content
pane of a JFrame - it's rendered correctly. However, as soon as I add
this into a JScrollPane, trouble begins. The image gets rendered, but
something then erases the image again with the default grey background,
writing on top of my rendered image. I've already tried to set the
JScrollPane to non-opaque, but no go. Any idea what's going on here?
So long,
Thomas