Java Code Examples for javax.swing.JLabel.revalidate()

The following are Jave code examples for showing how to use revalidate() of the javax.swing.JLabel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: JDigitalSimulator   File: Guitilities.java   Source Code and License Vote up 5 votes
public static void setFittingLabelSize(JLabel label, int width) {
	int wordWidth, lines=1, size=0;
	if(width<=0||label.getText().isEmpty())
		return;
	StringTokenizer words = new StringTokenizer(label.getText());
	FontMetrics metrics = label.getFontMetrics(label.getFont());
	while(words.hasMoreTokens())
		if((size+=(wordWidth=metrics.stringWidth(words.nextToken())))>width) {
			size = wordWidth;
			lines++;
		}
	label.setPreferredSize(new Dimension(width, lines*metrics.getHeight()));
	label.revalidate();
}