javauser-interfacejframesetbounds

setBounds value for width that will set width to minimum?


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?


Solution

  • 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.