Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5036022

JSpinner does not reflect new font on subsequent calls to setFont

    Details

    • Subcomponent:
    • Resolved In Build:
      b68
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        JSpinner reflects new font only once at runtime. After this even if setFont is invoked, it does not reflect the new font.

        Compile and Run JSpinnerTest.java

        A new Font is set in loop at runtime. Its noted that JSpinner reflects the new font for first loop. On subsequent loop, even though jSpinner.getFont returns the updated font, its not reflected on screen.
        Adding "JSpinnerTest.java" here so it will be visible to the community.


        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.*;

        public class JSpinnerTest {

            private static final String metal =
                "javax.swing.plaf.metal.MetalLookAndFeel";
            private static final String motif =
                "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
            private static final String windowsXP =
                "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
            private static final String windowsClassic =
                "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel";
            private static final String gtk =
                "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";

            static int fontSize = 20;
            static JSpinner spinner = new JSpinner();

            public static void main(String args[]) throws Exception {

                //UIManager.setLookAndFeel(windowsXP);

                JFrame frame = new JFrame();
                frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 50, 50));

                
                frame.getContentPane().add(spinner);

                frame.pack();
                frame.setVisible(true);

                Thread thread = new Thread() {

                    public void run() {

                        try {
                            sleep(3000);
                        } catch (Exception e) {}

                        while(true) {

                            Font font = new Font("dialog", Font.BOLD, fontSize);
                            spinner.setFont(font);
                            System.out.println(spinner.getFont());
                            fontSize += 5;

                            try {
                                sleep(2000);
                            } catch (Exception e) {}
                        }
                    }
                };
                thread.start();
            }
        }

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  serb Sergey Bylokhov
                  Reporter:
                  rmenonsunw Rakesh Menon (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: