void (Container parent) { Insets i = parent.getInsets(); int pw = parent.getWidth() - i.left - i.right; Dimension pref = myLabelContainer.getPreferredSize(); int w = Math.min(pw, pref.width); int h = pref.height; int x = i.left + pw - w; int y = i.top; myLabelContainer.setBounds(x, y, w, h); }