Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

repaint()????  RSS feed

 
william brown
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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??
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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().
 
nick adams
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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).

 
Tom Shanks
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Henrik �stman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Test "setVisible(true);" instead of "show();".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!