im trying to paint a big "hello world" on my frame / component. But I want to dynamically fit it to the size of the window. Therefore, every time I change the size of the window, the text should fit perfectly into the window.
I use the FontMetrics class, to which I assign a font, and a measure of the width and height of the character.
But it would be nice to have a way to pass the size of the component with the text, and the method returns the font that I need to use. Well, the font size for a particular font will be enough.
Something like that:
public int getFontSizeForDrawArea( int width, int height, String text, Font font) {
I am thinking of creating a method that measures the size of text, trying in a loop until the size is so close to the width and height of the window. But perhaps there is something ready to use.
source share