void () { final GroupLayout layout = new GroupLayout(this); setLayout(layout); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup( layout.createSequentialGroup() .addComponent(myMinLabel) .addComponent(myMinField) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 20, 20) .addComponent(myMaxLabel) .addComponent(myMaxField) ); layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(myMinLabel) .addComponent(myMinField) .addComponent(myMaxLabel) .addComponent(myMaxField) ); myMinField.getValueEditor().addListener(newValue -> { if (myMinField.getValueEditor().isValid(newValue) && myMaxField.getValue() < newValue) myMaxField.setValue(newValue); }); myMaxField.getValueEditor().addListener(newValue -> { if (myMaxField.getValueEditor().isValid(newValue) && myMinField.getValue() > newValue) myMinField.setValue(newValue); }); }