I have a situation where a user enters a String and my code makes a Jlabel for it and attempts to center it on a full screen JFrame/Pane. My problem is, to be able to accurately center it, I need to know its dimensions.
I need a way to figure out how long (wide) the JLabel should be so that it accomodates the length of the string and nothing more. I tried using the preferredSize() method that components have and it looked horrible (I passed a null value to let my UI determine the preferredSize). I know how to figure out the height that works (the size of the fontSize + 10px is usually good) but I can't get the width.
I am using absolute positioning (no LayoutManager).
Thanks