< prev index next >

src/java.desktop/share/classes/javax/swing/JSpinner.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -27,10 +27,12 @@
 
 import java.awt.*;
 import java.awt.event.*;
 
 import javax.swing.event.*;
+import javax.swing.plaf.FontUIResource;
+import javax.swing.plaf.UIResource;
 import javax.swing.text.*;
 import javax.swing.plaf.SpinnerUI;
 
 import java.util.*;
 import java.beans.*;

@@ -741,11 +743,12 @@
                 return;
             }
 
             Object source = e.getSource();
             String name = e.getPropertyName();
-            if ((source instanceof JFormattedTextField) && "value".equals(name)) {
+            if (source instanceof JFormattedTextField) {
+                if ("value".equals(name)) {
                 Object lastValue = spinner.getValue();
 
                 // Try to set the new value
                 try {
                     spinner.setValue(getTextField().getValue());

@@ -757,10 +760,21 @@
                         // Still bogus, nothing else we can do, the
                         // SpinnerModel and JFormattedTextField are now out
                         // of sync.
                     }
                 }
+                } else if ("font".equals(name)) {
+                    Object newfont = e.getNewValue();
+                    if (newfont instanceof UIResource) {
+                        // The text field font must match the JSpinner font if
+                        // the text field font was not set by the user
+                        Font font = spinner.getFont();
+                        if (!newfont.equals(font)) {
+                            getTextField().setFont(new FontUIResource(font));
+                        }
+                    }
+                }
             }
         }
 
 
         /**
< prev index next >