• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

repaint()????

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've created a class that extends a JPanel and I have override the paintComponent() method. The problem is, whenever I call a repaint() from another method ( doSomething()), the paintComponent() was not called. The doSomething() method is called when user click a button after he/she insert the 'a' and 'b' value into 2 textfields.
Why is that?

here is some of my code:

int x, y;

public void doSomething(int a, int b)
{
x = a;
y = b;
repaint();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawLine(x,y,x+50,y+50);
}

Any idea or suggestion??
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your paintComponent() ever get called? If not, then you need to try to determine if your JPanel is actually showing on screen anywhere. Perhaps it was never added to a container.
 
william brown
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. The paintComponent()will be called whenever I start to call the class, or minimizing the window any any other operation.. but not when I try to call it through doSomething().
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what you are trying to do. Here is a simple application that will repaint a panel for you. It will repaint the panel over and over inside the loop (waiting for the user to hit return).

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nick,

When I try and compile your code I get an error message detailing that the code contains some deprecated API. I am running java 1.5, I just wondered if you knew what part of the code was deprecated?

Regards,

Tom
 
nick adams
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't thing of anything right off the top of my head. I'll take a look around and see what I can find. I'm a little suprised that your IDE doesn't tell you what line is depriciated.

I'm using 1.4.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Test "setVisible(true);" instead of "show();".
 
reply
    Bookmark Topic Watch Topic
  • New Topic