desiboy1974
asked on
applet looks blurry or flickers
has anyone seen this?...when i lauch my applet, the iamges appear over another etc..as if its out of place..if i then minimise the applet and then maximise it, its all fine..or if i switch to another window and then back to it , its all fine..
Repainting problem(s)
You're not mixing AWT and Swing are you?
Any code?
post your paint method
All of the above ;-)
And check you have no operations holding up the EDT
ASKER
jPanel3.setBackground(new java.awt.Color(255,255,255
jPanel3 = new JImagePanel(img6);
jPanel1.add(jPanel3);
jPanel3.setBounds(400, 400, 280, 150);
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.image.ImageObserv
import java.applet.Applet;
public class JImagePanel extends JPanel
{
private Image img;
public JImagePanel(Image i)
{
this.img = i;
}
public Dimension getPreferredSize()
{
return new Dimension(5+img.getWidth(n
}
public void paint(Graphics g)
{
//super.paint(g);
g.drawImage(img, 10, 10, this);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
With Swing, you override paintComponent, not paint
The problem is probably elsewhere - possibly in something holding up the EDT
So:
public void paintComponent(Graphics g)
{
super.paintComponent( g );
g.drawImage(img, 10, 10, this);
}
public void paintComponent(Graphics g)
{
super.paintComponent( g );
g.drawImage(img, 10, 10, this);
}
>>
should be
public void paintComponent(Graphics g)
>>
LOL - missed that ;-)
should be
public void paintComponent(Graphics g)
>>
LOL - missed that ;-)
>> With Swing, you override paintComponent, not paint
Well,... you should only override paint() for top level containers (eg. JFrame)
Well,... you should only override paint() for top level containers (eg. JFrame)
> LOL - missed that ;-)
:-) I almost did too...
> Well,... you should only override paint() for top level containers (eg. JFrame)
True, as they don't extend JComponent...
:-) I almost did too...
> Well,... you should only override paint() for top level containers (eg. JFrame)
True, as they don't extend JComponent...
ASKER
tried that..same problem..
ASKER
public void paintComponent(Graphics g)
{
super.paint(g);
g.drawImage(img, 10, 10, this);
}
{
super.paint(g);
g.drawImage(img, 10, 10, this);
}
super.paint(g);
should be
super.paintComponent(g);
like I said...
should be
super.paintComponent(g);
like I said...
> super.paint(g);
will probably start a loop that will cause a StackOverflowException...
will probably start a loop that will cause a StackOverflowException...
If it isn't that, then it could be a probalem with your image loading (the image may not be loaded by the time the panel appears, and so getPreferredSize goes a bit mad...
Can you post your code where you load the image?
Can you post your code where you load the image?
>>tried that..same problem..
I suspected it wouldn't fix the problem totally, but it's nonetheless true. Have you any application threads running in event handlers?
I suspected it wouldn't fix the problem totally, but it's nonetheless true. Have you any application threads running in event handlers?
ASKER
thanks..it worked fine now..
:-) Cool :-)
Good luck with it :-)
Tim
Good luck with it :-)
Tim