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

JSpinner default layout manager does not allow removing "Next" button

XMLWordPrintable

    • b10
    • x86
    • linux, windows_2003
    • Verified

      FULL PRODUCT VERSION :
      java version "1.5.0_08"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 5.2.3790

      A DESCRIPTION OF THE PROBLEM :
      The default layout manager of JSpinner does not allow removing the arrow up button through its removeLayoutComponent method as it should, but it allows removing the arrow down button as well as the editor.

      there is a bug in the source code of BasicSpinnerUI version 1.15 03/01/23 on line 704. It should read of course "nextButton = null;" instead of "c = null;"


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;

      public class JSpinnerBug2
      {
          public static void main(String[] args)
          {
              // create a JSpinner and set a value
              JSpinner spinner = new JSpinner();
              spinner.setValue(new Integer(1234567890));
              
              // get the arrow buttons
              Component arrowUp = spinner.getComponent(0);
              Component arrowDown = spinner.getComponent(1);
              
              // try remove both buttons from the layout
              LayoutManager layout = spinner.getLayout();
              layout.removeLayoutComponent(arrowUp);
              layout.removeLayoutComponent(arrowDown);
              
              // create a frame and add the spinner spinner
              JFrame frame = new JFrame("Only the arrow down is missing");
              Container pane = frame.getContentPane();
              pane.setLayout(new FlowLayout());
              pane.add(spinner);
              
              // show the frame
              frame.setBounds(0, 0, 300, 150);
              frame.setVisible(true);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      remove the next button using addLayoutComponent("Next", null)
      better, subclass BasicSpinnerUI and write your own layout manager

            shickeysunw Shannon Hickey (Inactive)
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: