Skip to content

Commit

Permalink
Correct the size field no matter how the field is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrbysco committed Nov 25, 2024
1 parent 5cd7b3d commit 7701f11
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public SizeField(Font font, int x, int y, int width, int height, Component defau

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return super.keyPressed(keyCode, scanCode, modifiers);
boolean pressed = super.keyPressed(keyCode, scanCode, modifiers);
if (pressed) {
this.correctValue();
}
return pressed;
}

@Override
public void insertText(String textToWrite) {
if (this.isNumeric(textToWrite))
super.insertText(textToWrite);

this.correctValue();
}

private void correctValue() {
float currentValue = getFloat();
if (currentValue > maxValue)
this.setValue(String.valueOf(maxValue));
Expand Down

0 comments on commit 7701f11

Please sign in to comment.