Dimension () { final Dimension size = super.getPreferredSize(); if (myWidth == null) { myWidth = 10; final FontMetrics fm = getFontMetrics(getFont()); for (JLabel confLabel : map.values()) { String text = confLabel.getText(); myWidth += fm.stringWidth(text + "W"); } } return new Dimension(myWidth, size.height); }