So, there's a few other posts on Stackoverflow like Calculate the display width of a string in Java and How to calculate length of string in pixels for specific font and size? but the first one only calculates the width of the string from some pre-determined font and size, and the latter one is in Python.
Basically my goal is I want to make an application where there's a username, and the JLabel on it is exactly the length of the text. Since I don't know what the username is while designing the program, I can't know how far it is, but I want to know how to calculate that width of text with my font and size specified (and then I already know how to adjust the size of a JLabel).
Any ideas? Thanks!