Im working on a Marquee JPanel ,and im using a JLabel to scroll Text within the JPanel by Decreasing the Y of JLabel inside the JPanel .
The issue is i need a Specific Width of JLabel where Height is not important because it will scroll the Text until the Y of JLabel is > than -JLabel.Height which means JLabel last line of text is at Top of JPanel .
So how can i calculate the Height which can hold a sort of Text based on a specific value of Width .
eg.
If Width of JLabel is 50 than the Height should be that value that can fit the text within if text is “Bla bla bla some text over …” and font is “Serif”, Font.ITALIC, 20
Despite that this is answered, I thought I’d offer an alternative approach. This alternate boils down to ‘put the text it in an HTML formatted label’. The advantage of this approach is that line breaks are normally handled automatically, without having to worry about where to break each line. E.G.
Output
Caveat