This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I made a JPanel that prints some text (and some other nice stuff) overriding paint(Graphics g) method. As I'm using text, I need to use FontMetrics to retrieve the bounds of my text and print it on the center.
But depending on the text size, and container size, it shows up a little twisted in the screen.
When I resize the window, the text appears as expected. And when I resize back to the original position, the text keeps showing correctly.
Is there a method in JComponent or JPanel that does the same kind of update as a manual resize does? I want to make my text to appear on screen accordingly since the beginning. How can I update my screen programmatically instead of "manually"?
I tried updateUI(), repaint() and invalidate() methods. And none of these made the job.
Any help will be appreciated. Best Regards.
The art of being crazy is to NEVER commit the crazyness of being normal.
repaint() is what you're looking for. If it's not working then that would indicate to me it's not a problem with the painting. Look at what the resizing does to affect your variants and it's probably somewhere in there.
If you post some code I'll be happy to try and help.