Hi!
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.
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.