Browse Source

REPORT-53949 UIBoundSpinner也需要获取焦点后滚动修改值

zheng-1641779399395
kuangshuai 3 years ago
parent
commit
9ae5af1164
  1. 12
      designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java
  2. 6
      designer-form/src/main/java/com/fr/design/widget/ui/designer/component/UIBoundSpinner.java

12
designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java

@ -58,7 +58,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
* Spinner内的数字文本框长度 * Spinner内的数字文本框长度
*/ */
private int numberFieldColumns; private int numberFieldColumns;
private boolean hasTextFieldFocus = false; private boolean textFieldFocus = false;
public UISpinner() { public UISpinner() {
@ -197,6 +197,10 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
this.nextButton.setEnabled(flag); this.nextButton.setEnabled(flag);
} }
public void setTextFieldFocus(boolean textFieldFocus) {
this.textFieldFocus = textFieldFocus;
}
@Override @Override
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize(); Dimension dim = super.getPreferredSize();
@ -319,7 +323,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
@Override @Override
public void mouseWheelMoved(MouseWheelEvent e) { public void mouseWheelMoved(MouseWheelEvent e) {
if (hasTextFieldFocus && isEnabled() && e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { if (textFieldFocus && isEnabled() && e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
setValue(value - e.getWheelRotation()); setValue(value - e.getWheelRotation());
} }
} }
@ -333,12 +337,12 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
textField.addFocusListener(new FocusAdapter() { textField.addFocusListener(new FocusAdapter() {
@Override @Override
public void focusGained(FocusEvent e) { public void focusGained(FocusEvent e) {
hasTextFieldFocus = true; textFieldFocus = true;
} }
@Override @Override
public void focusLost(FocusEvent e) { public void focusLost(FocusEvent e) {
hasTextFieldFocus = false; textFieldFocus = false;
textField.getDocument().removeDocumentListener(docListener); textField.getDocument().removeDocumentListener(docListener);
textField.setValue(value); textField.setValue(value);
textField.getDocument().addDocumentListener(docListener); textField.getDocument().addDocumentListener(docListener);

6
designer-form/src/main/java/com/fr/design/widget/ui/designer/component/UIBoundSpinner.java

@ -23,8 +23,14 @@ public class UIBoundSpinner extends UISpinner{
@Override @Override
protected void initTextFiledListeners(){ protected void initTextFiledListeners(){
this.getTextField().addFocusListener(new FocusAdapter() { this.getTextField().addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
setTextFieldFocus(true);
}
@Override @Override
public void focusLost(FocusEvent e) { public void focusLost(FocusEvent e) {
setTextFieldFocus(false);
setTextFieldValue(getTextField().getValue()); setTextFieldValue(getTextField().getValue());
setTextField(value); setTextField(value);
} }

Loading…
Cancel
Save