📄 scrollpane.html
字号:
for specifying this policy: <code>VERTICAL_SCROLLBAR_AS_NEEDED</code> (the default), <code>VERTICAL_SCROLLBAR_ALWAYS</code>, and <code>VERTICAL_SCROLLBAR_NEVER</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html#setHorizontalScrollBarPolicy(int)">void setHorizontalScrollBarPolicy(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html#getHorizontalScrollBarPolicy()">int getHorizontalScrollBarPolicy()</a> </td> <td>Set or get the horizontal scroll policy. <code>ScrollPaneConstants</code> defines three values for specifying this policy: <code>HORIZONTAL_SCROLLBAR_AS_NEEDED</code> (the default), <code>HORIZONTAL_SCROLLBAR_ALWAYS</code>, and <code>HORIZONTAL_SCROLLBAR_NEVER</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html#setViewportBorder(javax.swing.border.Border)">void setViewportBorder(Border)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html#getViewportBorder()">Border getViewportBorder()</a> </td> <td>Set or get the border around the viewport. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html#setWheelScrollingEnabled(boolean)">void setWheelScrollingEnabled(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html#isWheelScrollingEnabled()">boolean isWheelScrollingEnabled()</a> </td> <td>Set or get whether scrolling occurs in response to the mouse wheel. Mouse-wheel scrolling is enabled by default. </td> </tr></table><p><table border=1><caption><a name="decorationsAPI">Decorating the Scroll Pane</a><br>(<code>JScrollPane</code> methods)</caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html#setColumnHeaderView(java.awt.Component)">void setColumnHeaderView(Component)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html#setRowHeaderView(java.awt.Component)">void setRowHeaderView(Component)</a> </td> <td>Set the column or row header for the scroll pane. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html#setCorner(java.lang.String, java.awt.Component)">void setCorner(String, Component)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html#getCorner(java.lang.String)">Component getCorner(String)</a> </td> <td>Set or get the corner specified. The <code>int</code> parameter specifies which corner and must be one of the following constants defined in <code>ScrollPaneConstants</code>: <code>UPPER_LEFT_CORNER</code>, <code>UPPER_RIGHT_CORNER</code>, <code>LOWER_LEFT_CORNER</code>, <code>LOWER_RIGHT_CORNER</code>, <code>LOWER_LEADING_CORNER</code>, <code>LOWER_TRAILING_CORNER</code>, <code>UPPER_LEADING_CORNER</code>, and <code>UPPER_TRAILING_CORNER</code>. </td> </tr></table><p><table border=1><caption><a name="scrollableAPI">Implementing a Scrolling-Savvy Client</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/Scrollable.html#getScrollableUnitIncrement(java.awt.Rectangle, int, int)">int getScrollableUnitIncrement(Rectangle, int, int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/Scrollable.html#getScrollableBlockIncrement(java.awt.Rectangle, int, int)">int getScrollableBlockIncrement(Rectangle, int, int)</a> <br> <em>(required by the <code>Scrollable</code> interface)</em> </td> <td>Get the unit or block increment in pixels. The <code>Rectangle</code> parameter is the bounds of the currently visible rectangle. The first <code>int</code> parameter is either <code>SwingConstants.HORIZONTAL</code> or <code>SwingConstants.VERTICAL</code> depending on what scroll bar the user clicked on. The second <code>int</code> parameter indicates which direction to scroll. A value less than 0 indicates up or left. A value greater than 0 indicates down or right. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/Scrollable.html#getPreferredScrollableViewportSize()">Dimension getPreferredScrollableViewportSize()</a> <br> <em>(required by the <code>Scrollable</code> interface)</em> </td> <td>Get the preferred size of the viewport. This allows the client to influence the size of the viewport in which it is displayed. If the viewport size is unimportant, implement this method to return <code>getPreferredSize</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/Scrollable.html#getScrollableTracksViewportWidth()">boolean getScrollableTracksViewportWidth()</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/Scrollable.html#getScrollableTracksViewportHeight()">boolean getScrollableTracksViewportHeight()</a> <br> <em>(required by the <code>Scrollable</code> interface)</em> </td> <td>Get whether the scroll pane should force the client to be the same width or height as the viewport. A return value of <code>true</code> from either of these methods effectively disallows horizontal or vertical scrolling (respectively). </td> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#setAutoscrolls(boolean)">void setAutoscrolls(boolean)</a> <br> <em>(in <code>JComponent</code>)</em> </td> <td>Set whether synthetic mouse dragged events should be generated when the user drags the mouse outside of the component and stops; these events are necessary for scrolling by dragging. By default, the value is <code>false</code>, but many scrollable components such as <code>JTable</code> and custom components set the value to <code>true</code>. </td> </tr> </tr></table><p><table border=1><caption><a name="otherAPI">Methods in Other Classes Related to Scrolling</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#scrollRectToVisible(java.awt.Rectangle)">void scrollRectToVisible(Rectangle)</a> <br> <em>(in <code>JComponent</code>)</em> </td> <td>If the component is in a container that supports scrolling, such as a scroll pane, then calling this method scrolls the scroll pane such that the specified rectangle is visible. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JList.html#setVisibleRowCount(int)">void setVisibleRowCount(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JList.html#getVisibleRowCount()">int getVisibleRowCount()</a> <br> <em>(in <code>JList</code>)</em> </td> <td>Set or get how many rows of the list are visible. The <code>getPreferredScrollableViewportSize</code> method uses the visible row count to compute its return value. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JList.html#ensureIndexIsVisible(int)">void ensureIndexIsVisible(int)</a> <br> <em>(in <code>JList</code>)</em> </td> <td>Scroll so that the row at the specified index is visible. This method calls <code>scrollRectToVisible</code> and works only if the list is in a container, such as a scroll pane, that supports scrolling. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#setVisibleRowCount(int)">void setVisibleRowCount(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#getVisibleRowCount()">int getVisibleRowCount()</a> <br> <em>(in <code>JTree</code>)</em> </td> <td>Set or get how many rows of the tree are visible. The <code>getPreferredScrollableViewportSize</code> method uses the visible row count to compute its return value. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#scrollPathToVisible(javax.swing.tree.TreePath)">void scrollPathToVisible(TreePath)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#scrollRowToVisible(int)">void scrollRowToVisible(int)</a> <br> <em>(in <code>JTree</code>)</em> </td> <td>Scroll so that the specified tree path or row at the specified index is visible. These methods call <code>scrollRectToVisible</code> and work only if the tree is in a container, such as a scroll pane, that supports scrolling. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#setScrollsOnExpand(boolean)">void setScrollsOnExpand(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#getScrollsOnExpand()">boolean getScrollsOnExpand()</a> <br> <em>(in <code>JTree</code>)</em> </td> <td>Set or get whether scrolling occurs automatically when the user expands a node. True by default. This feature works only when the tree is in a container, such as a scroll pane, that supports scrolling. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTable.html#setPreferredScrollableViewportSize(java.awt.Dimension)">void setPreferredScrollableViewportSize(Dimension)</a> <br> <em>(in <code>JTable</code>)</em> </td> <td>Set the value to be returned by <code>getPreferredScrollableViewportSize</code>. </td> </tr></table></blockquote><h3><a name="eg">Examples that Use Scroll Panes</a></h3><blockquote>This table shows the examples that use <code>JScrollPane</code>and where those examples are described.<p><table><tr><th align=left> Example</th><th align=left> Where Described</th><th align=left> Notes</th></tr><tr><td> <a href="examples/index.html#ToolBarDemo"><code>ToolBarDemo</code></a></td><td> This section,<br> <a href="toolbar.html">How to Use Tool Bars</a></td><td> Shows a simple, yet typical, use of a scroll pane.</td></tr><tr><td> <a href="examples/index.html#ScrollDemo"><code>ScrollDemo</code></a></td><td> This section</td><td> Uses many of scroll pane's bells and whistles.</td></tr><tr><td> <a href="examples/index.html#ScrollDemo2"><code>ScrollDemo2</code></a></td><td> This section</td><td> Shows how to change the client's size.</td></tr><tr><td> <a href="examples/index.html#SplitPaneDemo"><code>SplitPaneDemo</code></a></td><td> <a href="splitpane.html">How to Use Split Panes</a>,<br> <a href="list.html">How to Use Lists</a></td><td> Puts a list and a label in a scroll pane. Also, shows how to handle the case when a scroll pane's client changes size.</td></tr><tr><td> <a href="examples/index.html#TableDemo"><code>TableDemo</code></a></td><td> <a href="table.html">How to Use Tables</a></td><td> Puts a table in a scroll pane.</td></tr><tr><td> <a href="examples/index.html#TextSamplerDemo"><code>TextSamplerDemo</code></a></td><td> <a href="text.html">Using Text Components</a></td><td> Puts a text area, an editor pane, and a text pane each in a scroll pane.</td></tr><tr><td> <a href="examples/index.html#TreeDemo"><code>TreeDemo</code></a></td><td> <a href="tree.html">How to Use Trees</a></td><td> Puts a tree in a scroll pane.</td></tr></table></blockquote> </blockquote> <div class=NavBit> <a target=_top href=rootpane.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=separator.html>Next »</a> </div> </div> <div id=Footer><div id=TagNotes> Problems with the examples? Try <a target="_blank" href=../../information/run-examples.html>Compiling and Running the Examples: FAQs</a>. <br> Complaints? Compliments? Suggestions? <a target="_blank" href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give us your feedback</a>.<br><br> <a target="_blank" href="../../information/copyright.html">Copyright</a> 1995-2006 Sun Microsystems, Inc. All rights reserved. <span id=Download></span></div> </div> <div class=PrintHeaders> <b>Previous page:</b> How to Use Root Panes <br><b>Next page:</b> How to Use Separators </div> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -