Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2007

Tip: Looking for answers? Try searching our database.

Refresh screen by repaint() mothed

Thread view: 
liang.spark@gmail.com - 24 Dec 2007 11:12 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.