1 /*
   2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 6532833 7077259
  26  * @summary PIT: Metal LAF - The right side border is not shown for the Spinner after the removing the buttons
  27  * @author Pavel Porvatov
  28  * @run main/othervm -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel bug6532833
  29  */
  30 
  31 import javax.swing.*;
  32 import java.awt.*;
  33 
  34 public class bug6532833 {
  35     public static void main(String[] args) throws Exception {
  36         SwingUtilities.invokeAndWait(new Runnable() {
  37             public void run() {
  38                 JSpinner[] spinners = new JSpinner[2];
  39 
  40                 for (int i = 0; i < spinners.length; i++) {
  41                     JSpinner spinner = new JSpinner();
  42 
  43                     spinner.setValue(2010);
  44 
  45                     Component arrowUp = spinner.getComponent(0);
  46                     Component arrowDown = spinner.getComponent(1);
  47 
  48                     LayoutManager layout = spinner.getLayout();
  49 
  50                     layout.removeLayoutComponent(arrowUp);
  51                     layout.removeLayoutComponent(arrowDown);
  52 
  53                     if (i == 1) {
  54                         spinner.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
  55                     }
  56 
  57                     spinners[i] = spinner;
  58                 }
  59 
  60                 // Do layout of spinners components
  61                 JFrame frame = new JFrame();
  62 
  63                 for (JSpinner spinner : spinners) {
  64                     frame.getContentPane().add(spinner);
  65                 }
  66 
  67                 frame.pack();
  68 
  69                 for (JSpinner spinner : spinners) {
  70                     Insets insets = spinner.getInsets();
  71 
  72                     if (spinner.getWidth() != insets.left + insets.right + spinner.getEditor().getWidth()) {
  73                         throw new RuntimeException("Spinner editor width is invalid");
  74                     }
  75                 }
  76 
  77                 frame.dispose();
  78             }
  79         });
  80     }
  81 }