src/share/classes/java/awt/ScrollPane.java

Print this page




 230         }
 231     }
 232 
 233     // The scrollpane won't work with a windowless child... it assumes
 234     // it is moving a child window around so the windowless child is
 235     // wrapped with a window.
 236     private void addToPanel(Component comp, Object constraints, int index) {
 237         Panel child = new Panel();
 238         child.setLayout(new BorderLayout());
 239         child.add(comp);
 240         super.addImpl(child, constraints, index);
 241         validate();
 242     }
 243 
 244     /**
 245      * Adds the specified component to this scroll pane container.
 246      * If the scroll pane has an existing child component, that
 247      * component is removed and the new one is added.
 248      * @param comp the component to be added
 249      * @param constraints  not applicable
 250      * @param index position of child component (must be <= 0)
 251      */
 252     protected final void addImpl(Component comp, Object constraints, int index) {
 253         synchronized (getTreeLock()) {
 254             if (getComponentCount() > 0) {
 255                 remove(0);
 256             }
 257             if (index > 0) {
 258                 throw new IllegalArgumentException("position greater than 0");
 259             }
 260 
 261             if (!SunToolkit.isLightweightOrUnknown(comp)) {
 262                 super.addImpl(comp, constraints, index);
 263             } else {
 264                 addToPanel(comp, constraints, index);
 265             }
 266         }
 267     }
 268 
 269     /**
 270      * Returns the display policy for the scrollbars.




 230         }
 231     }
 232 
 233     // The scrollpane won't work with a windowless child... it assumes
 234     // it is moving a child window around so the windowless child is
 235     // wrapped with a window.
 236     private void addToPanel(Component comp, Object constraints, int index) {
 237         Panel child = new Panel();
 238         child.setLayout(new BorderLayout());
 239         child.add(comp);
 240         super.addImpl(child, constraints, index);
 241         validate();
 242     }
 243 
 244     /**
 245      * Adds the specified component to this scroll pane container.
 246      * If the scroll pane has an existing child component, that
 247      * component is removed and the new one is added.
 248      * @param comp the component to be added
 249      * @param constraints  not applicable
 250      * @param index position of child component (must be &lt;= 0)
 251      */
 252     protected final void addImpl(Component comp, Object constraints, int index) {
 253         synchronized (getTreeLock()) {
 254             if (getComponentCount() > 0) {
 255                 remove(0);
 256             }
 257             if (index > 0) {
 258                 throw new IllegalArgumentException("position greater than 0");
 259             }
 260 
 261             if (!SunToolkit.isLightweightOrUnknown(comp)) {
 262                 super.addImpl(comp, constraints, index);
 263             } else {
 264                 addToPanel(comp, constraints, index);
 265             }
 266         }
 267     }
 268 
 269     /**
 270      * Returns the display policy for the scrollbars.