scrollpane.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 618 行 · 第 1/2 页
JAVA
618 行
}/*************************************************************************//** * Returns the width of a vertical scrollbar. * * @return The width of a vertical scrollbar. */public intgetVScrollbarWidth(){ ScrollPanePeer spp = (ScrollPanePeer)getPeer(); if (spp != null) return(spp.getVScrollbarWidth()); else return(0); // FIXME: What to do here?}/*************************************************************************//** * Returns the current scroll position of the viewport. * * @return The current scroll position of the viewport. */public PointgetScrollPosition(){ int x = 0; int y = 0; Adjustable v = getVAdjustable(); Adjustable h = getHAdjustable(); if (v != null) y = v.getValue(); if (h != null) x = h.getValue(); return(new Point(x, y));}/*************************************************************************//** * Sets the scroll position to the specified value. * * @param scrollPosition The new scrollPosition. * * @exception IllegalArgumentException If the specified value is outside * the legal scrolling range. */public voidsetScrollPosition(Point scrollPosition) throws IllegalArgumentException{ setScrollPosition(scrollPosition.x, scrollPosition.y);}/*************************************************************************//** * Sets the scroll position to the specified value. * * @param x The new X coordinate of the scroll position. * @param y The new Y coordinate of the scroll position. * * @exception IllegalArgumentException If the specified value is outside * the legal scrolling range. */public voidsetScrollPosition(int x, int y){ Adjustable h = getHAdjustable(); Adjustable v = getVAdjustable(); if (h != null) h.setValue(x); if (v != null) v.setValue(y); ScrollPanePeer spp = (ScrollPanePeer)getPeer(); if (spp != null) spp.setScrollPosition(x, y);}/*************************************************************************//** * Notifies this object that it should create its native peer. */public voidaddNotify(){ if (peer != null) return; setPeer((ComponentPeer)getToolkit().createScrollPane(this)); super.addNotify(); Component[] list = getComponents(); if (list != null && list.length > 0 && ! (list[0] instanceof Panel)) { Panel panel = new Panel(); panel.setLayout(new BorderLayout()); panel.add(list[0], BorderLayout.CENTER); add(panel); }}/*************************************************************************//** * Notifies this object that it should destroy its native peers. */public voidremoveNotify(){ super.removeNotify();}/*************************************************************************//** * Adds the specified child component to this container. A * <code>ScrollPane</code> can have at most one child, so if a second * one is added, then first one is removed. * * @param component The component to add to this container. * @param constraints A list of layout constraints for this object. * @param index The index at which to add the child, which is ignored * in this implementation. */ protected final void addImpl (Component component, Object constraints, int index){ Component[] list = getComponents(); if ((list != null) && (list.length > 0)) remove(list[0]); super.addImpl(component, constraints, -1); doLayout();}/*************************************************************************//** * Lays out this component. This consists of resizing the sole child * component to its perferred size. */public voiddoLayout(){ layout ();}/*************************************************************************//** * Lays out this component. This consists of resizing the sole child * component to its perferred size. * * @deprecated This method is deprecated in favor of * <code>doLayout()</code>. */public voidlayout(){ Component[] list = getComponents (); if ((list != null) && (list.length > 0)) { Dimension dim = list[0].getPreferredSize (); Dimension vp = getViewportSize (); if (dim.width < vp.width) dim.width = vp.width; if (dim.height < vp.height) dim.height = vp.height; ScrollPanePeer peer = (ScrollPanePeer) getPeer (); if (peer != null) peer.childResized (dim.width, dim.height); list[0].setSize (dim); Point p = getScrollPosition (); if (p.x > dim.width) p.x = dim.width; if (p.y > dim.height) p.y = dim.height; setScrollPosition (p); }}/*************************************************************************//** * This method overrides its superclass method to ensure no layout * manager is set for this container. <code>ScrollPane</code>'s do * not have layout managers. * * @param layoutManager Ignored */public final voidsetLayout(LayoutManager layoutManager){ return;}/*************************************************************************//** * Prints all of the components in this container. * * @param graphics The desired graphics context for printing. */public voidprintComponents(Graphics graphics){ super.printComponents(graphics);}/*************************************************************************//** * Returns a debug string for this object. * * @return A debug string for this object. */public StringparamString(){ Insets insets = getInsets(); return getName() + "," + getX() + "," + getY() + "," + getWidth() + "x" + getHeight() + "," + "ScrollPosition=(" + scrollPosition.getX() + "," + scrollPosition.getY() + ")," + "Insets=(" + insets.top + "," + insets.left + "," + insets.bottom + "," + insets.right + ")," + "ScrollbarDisplayPolicy=" + getScrollbarDisplayPolicy() + "," + "wheelScrollingEnabled=" + isWheelScrollingEnabled();} /** * Tells whether or not an event is enabled. * * @since 1.4 */ protected boolean eventTypeEnabled (int type) { if (type == MouseEvent.MOUSE_WHEEL) return wheelScrollingEnabled; return super.eventTypeEnabled (type); } /** * Tells whether or not wheel scrolling is enabled. * * @since 1.4 */ public boolean isWheelScrollingEnabled () { return wheelScrollingEnabled; } /** * Enables/disables wheel scrolling. * * @since 1.4 */ public void setWheelScrollingEnabled (boolean enable) { wheelScrollingEnabled = enable; } protected class AccessibleAWTScrollPane extends AccessibleAWTContainer { private static final long serialVersionUID = 6100703663886637L; public AccessibleRole getAccessibleRole() { return AccessibleRole.SCROLL_PANE; } } /** * Gets the AccessibleContext associated with this <code>ScrollPane</code>. * The context is created, if necessary. * * @return the associated context */ public AccessibleContext getAccessibleContext() { /* Create the context if this is the first request */ if (accessibleContext == null) accessibleContext = new AccessibleAWTScrollPane(); return accessibleContext; }} // class ScrollPane
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?