setBounds value for width that will set width to minimum?

228 Views Asked by At

Is there a value that can be put into setBounds to set the width to the minimum needed?

JLabel title = new JLabel("Title Text");
title.setBounds(50, 20, ?, 13);

Rather than using guess & check to find the minimum width, is there a value I can use?

1

There are 1 best solutions below

4
Shannon On BEST ANSWER

If you already know the text that will be in the JLabel (i.e., if that text won't change after being assigned once), there is no need to set the minimum width; the JLabel should do so automatically.