So I have a JLabel
here that's text is set from a String taken from a file seen here:
Label lName = new JLabel("Charater Name: " + data[FileIO.NAME]);
lName.setForeground(Color.WHITE);
lName.setBounds(640 - 110, 5, 110, 30);
add(lName);
Since the name could be 3 letters long to 24 letters long I don't want to use a fixed width, I want the label's width to wrap around the text enough so that the text isn't cut off but so that it's not wasting a bunch of space, how can I do this?
Edit: The JLabel's location will be set programmatically depending on it's width.
Currently my only solution is setting the width to this:
(int) (lName.getText().length() * (double) 6.8)
Which lasts for around 40 letters before being cut off.