Hi here,
In my cast.
class MyFrame extends JFrame{
public void paint(Graphics g){
g.drawText("some word");
}
}
Every time I call repaint() mothed. the application screen twinkled.
If i call repaint() frequently. the screen continuously fresh. It's
serious problem for user experience.
how can I avoid this problem?
I appreciate to any suggestion!
liang xiao
Andrew Thompson - 24 Dec 2007 13:26 GMT
...
>In my cast.
In your what?
>class MyFrame extends JFrame{
> public void paint(Graphics g){
> g.drawText("some word");
> }
>}
What is this rubbish? It does not compile, let alone
run. Why would you waste our bandwidth?
>I appreciate to any suggestion!
Post only SSCCEs. E.G.
<sscce>
import java.awt.*;
import javax.swing.*;
class MyFrame extends JFrame{
MyFrame() {
super("My Frame");
getContentPane().add(
new CustomLabel("Hello World!") );
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
}
public static void main(String[] args) {
MyFrame frame = new MyFrame();
frame.setVisible(true);
}
}
class CustomLabel extends JLabel {
String text;
CustomLabel(String text) {
this.text = text;
setPreferredSize( new Dimension(200,50) );
}
public void paintComponent(Graphics g){
g.setColor(Color.black);
g.drawString(text,40,40);
}
}
</sscce>

Signature
Andrew Thompson
http://www.physci.org/
Daniel Pitts - 24 Dec 2007 19:49 GMT
> Hi here,
>
[quoted text clipped - 12 lines]
>
> liang xiao
Don't override paint.
Create your own subclass of JComponent, and override paintComponent.
You're flashing should go away.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
liang.spark@gmail.com - 27 Dec 2007 05:33 GMT
On Dec 25, 3:49 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.net> wrote:
> liang.sp...@gmail.com wrote:
> > Hi here,
[quoted text clipped - 21 lines]
> --
> Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
I'm sorry my mistake in my original post. it should be below:
g.drawString("some word",0,0);
I try to extends JPanal. and use setContentPanel mothed of JFrame to
my customer Panel. override paintComponent() mothed. the flashing was
gone.
thank you both of above.
Roedy Green - 27 Dec 2007 23:46 GMT
On Mon, 24 Dec 2007 03:12:46 -0800 (PST), "liang.spark@gmail.com"
<liang.spark@gmail.com> wrote, quoted or indirectly quoted someone who
said :
>}
>Every time I call repaint() mothed. the application screen twinkled.
>If i call repaint() frequently. the screen continuously fresh. It's
>serious problem for user experience.
>how can I avoid this problem?
see http://mindprod.com/jgloss/flicker.html
http://mindprod.com/jgloss/paint.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Roedy Green - 31 Dec 2007 12:52 GMT
On Mon, 24 Dec 2007 03:12:46 -0800 (PST), "liang.spark@gmail.com"
<liang.spark@gmail.com> wrote, quoted or indirectly quoted someone who
said :
>Every time I call repaint() mothed. the application screen twinkled.
>If i call repaint() frequently. the screen continuously fresh. It's
>serious problem for user experience.
Normally you don't have to call repaint. It happens as a side effect
of other work.
See http://mindprod.com/jgloss/repaint.html
http://mindprod.com/jgloss/flicker.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com