Instead of that mayby use setMinimumSize(), setMaximumSize() ?