File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

repaint happens only on mouseclick

 
Viktoria Silver
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to draw a graph in my app.
I have created a separate class for it which extends jPanel.

when launching the app I create an instance of this class:

here's the constructor of that class if it matters any:

On a button click I launch the following code:

I can see in the console that every line of that code is passed, number 1 through 3 are printed. But nothing happens on the jPanel7. BUT when after the button press I click with the mouse in the area where the graph should be, it is drawn.

Here's the code of repaint, it works, but, as I said, only on a consequent mouse click.


Thank you for your time, it's appreciated.
 
Rob Camick
Ranch Hand
Posts: 2473
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bits of random code don't show the context of how your code is used.

Post your SSCCE that demonstrates the problem.
 
Viktoria Silver
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it solved, thanks.
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you like to share your solution, so others with the same problem can use it?
 
Viktoria Silver
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like repaint() works on Graphics class instance only if it has already been painted before. I don't know if there is a way to code an app initiated first time paint, but it is done automatically by system on some occasions.

My app has a jTabbedPane with multiple tab pages. I set it up in a way that the graph is first drawn (using repaint()) right after data is loaded into the app. it happens on the first tab, but the graph is on the third tab. Then when user clicks on the tab with the graph a system initiated first paint happens automatically.
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Viktoria Silver wrote:It looks like repaint() works on Graphics class instance only if it has already been painted before.

That's just wrong.

You were asked for an SSCCE. If you really want to know what's wrong with your code, now would be a good time to post it.
 
Viktoria Silver
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you're right it is a wrong process that gives a right result. I guess I don't really care about the process, I just need the result.
It took me less time to get to this right result the wrong way than it would take me to create SSCCE, wait if you can hint me to the right process and then implement it.

thanks for your passionate willingness to help.

 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Viktoria Silver wrote:you're right it is a wrong process that gives a right result.


But it's not the right result as it will easily break.

I guess I don't really care about the process, I just need the result.


This won't work, not for programming.


It took me less time to get to this right result the wrong way than it would take me to create SSCCE, wait if you can hint me to the right process and then implement it.


We can't really hint if we don't have a decent understanding of what you're trying to do, hence the request for an SSCCE. My advice is still that you create one and post it so that we do have enough information to provide you with decent advice on how to do it right -- but only if you care about learning programming.
 
Sven Goetgeluck
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

try
SwingUtilities.UpdateComponentTree(optgr );

when you want to repaint

Sven
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sven Goetgeluck wrote:hello,

try
SwingUtilities.UpdateComponentTree(optgr );

when you want to repaint

Sven

Sven, please don't post bad advice. Which could only have been worse if you recommended a method with a somewhat similar name that actually exists. This one doesn't.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic