What is the difference between jscrollpane and jscrollbar




















This method returns the height of the visible rectangle minus a tick mark. This behavior is typical, but true if scrolling vertically, otherwise, it's the width. A block increment should be slightly smaller than the viewport to leave a little of the previous visible area for context. For example, a text area might leave one or two lines of text for context and a table might leave a row or column depending on the scroll direction. The boldface code in the following snippet implements scrolling by dragging:.

This snippet scrolls the picture whenever the user drags from the picture to a location outside the picture and pauses. Setting the autoscrolls property to true makes the component fire synthetic mouse-dragged events even when the mouse isn't moving because it stopped, mid-drag, outside the component. It's up to the component's mouse motion listener to listen for these events and react accordingly.

Unless you explicitly set a scroll pane's preferred size, the scroll pane computes it based on the preferred size of its nine components the viewport, and, if present, the two scroll bars, the row and column headers, and the four corners. The largest factor, and the one most programmers care about, is the size of the viewport used to display the client. If the client is not scrolling-savvy, then the scroll pane sizes itself so that the client displays at its preferred size.

For typical unsavvy clients, this makes the scroll pane redundant. That is, the scroll pane has no scroll bars because the client's preferred size is big enough to display the entire client. In this case, if the client doesn't change size dynamically, you should probably limit the size of the scroll pane by setting its preferred size or the preferred size of its container. If the client is scrolling-savvy, then the scroll pane uses the value returned by the client's getPreferredScrollableViewportSize method to compute the size of its viewport.

Implementations of this method generally report a preferred size for scrolling that's smaller than the component's standard preferred size. For example, by default, the value returned by JList 's implementation of getPreferredScrollableViewportSize is just big enough to display eight rows. Scrolling-savvy classes, like lists , tables , text components , and trees , often provide one or more methods that let programmers affect the size returned from getPreferredScrollableViewportSize.

For example, you can set the number of visible rows in a list or a tree by calling the setVisibleRowCount method. The list or tree takes care of figuring out the size needed to display that number of rows. Changing the size of a scroll pane's client is a two-step process. First, set the client's preferred size. Then, call revalidate on the client to let the scroll pane know that it should update itself and its scroll bars.

Let's look at an example. Here's a picture of an application that changes the client's size whenever the user places a circle whose bounds fall outside of the client's current bounds. The program also changes the client's size when the user clears the drawing area:. You can find the full source code for this example in ScrollDemo2. Note that when the client changes size, the scroll bars adjust. The scroll pane doesn't resize, nor does the viewport.

Refer to SplitPaneDemo for another example in which the client object changes size. The following tables list the commonly used scroll-related constructors and methods.

Other methods you are most likely to invoke on a JScrollPane object are those such as setPreferredSize that its superclasses provide. This table shows the examples that use JScrollPane and where those examples are described.

All rights reserved. Hide TOC. Using Swing Components. Alternatively, to compile and run the example yourself, consult the example index. Move the knobs on the scroll bars. Watch the image scroll and the horizontal and vertical rulers scroll along. If you have a mouse with a wheel which is generally between the mouse buttons use the mouse wheel to scroll the image vertically.

Click the cm toggle in the upper left corner of the scroll pane. The units on the row and column headers change to inches or back to centimeters.

Click the arrow buttons on the scroll bars. Also, try clicking on the track above or below the knob on the vertical scroll bar, or to the left or right of the horizontal one.

Move the cursor over the image and press the cursor. Continuing to press the cursor, drag to a point outside the image and pause. The visible area of the image moves toward the cursor. This scroll-by-dragging functionality is enabled by the scroll pane, and with the JComponent API, but it is implemented by the custom component that displays the image.

The elements are of different sizes and may occupy more than one row or column of the grid. Thus, the rows and columns may have different sizes. The Frame class extends the Window class and defines a main application window that can have a menu bar.

When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting. An event-listener interface defines the methods that must be implemented by an event handler for a particular event.

An event adapter provides a default implementation of an event-listener interface. A GUI component can handle its own events, by implementing the corresponding event-listener interface and adding itself as its own event listener. Java uses layout managers to lay out components in a consistent manner, across all windowing platforms.

Serif Sans. JScrollBar getHorizontalScrollBar Returns the horizontal scroll bar that controls the viewport's horizontal view position. JViewport getRowHeader Returns the row header. Border getViewportBorder Returns the Border object that surrounds the viewport. Rectangle getViewportBorderBounds Returns the bounds of the viewport's border. Methods inherited from class javax.

Object clone , equals , finalize , getClass , hashCode , notify , notifyAll , wait , wait , wait Field Detail verticalScrollBarPolicy protected int verticalScrollBarPolicy The display policy for the vertical scrollbar. The default is ScrollPaneConstants.

Default is an empty JViewport. See Also: setViewport javax. Default is a JScrollBar. See Also: setVerticalScrollBar javax. See Also: setHorizontalScrollBar javax. Default is null. See Also: setRowHeader javax. See Also: setColumnHeader javax. See Also: setCorner java. Component lowerRight protected Component lowerRight The component to display in the lower right corner.

Component upperLeft protected Component upperLeft The component to display in the upper left corner. Component upperRight protected Component upperRight The component to display in the upper right corner.

Parameters: view - the component to display in the scrollpanes viewport vsbPolicy - an integer that specifies the vertical scrollbar policy hsbPolicy - an integer that specifies the horizontal scrollbar policy See Also: setViewportView java. Component JScrollPane public JScrollPane Component view Creates a JScrollPane that displays the contents of the specified component, where both horizontal and vertical scrollbars appear whenever the component's contents are larger than the view.

Parameters: view - the component to display in the scrollpane's viewport See Also: setViewportView java. Parameters: vsbPolicy - an integer that specifies the vertical scrollbar policy hsbPolicy - an integer that specifies the horizontal scrollbar policy See Also: setViewportView java. To be called when the default look and feel changes. This method overrides setLayout in java. If layout is non-null, this will invoke syncWithScrollPane on it. LayoutManager isValidateRoot public boolean isValidateRoot Overridden to return true so that any calls to revalidate on any descendants of this JScrollPane will cause the entire tree beginning with this JScrollPane to be validated.

Legal values are: ScrollPaneConstants. The options are: ScrollPaneConstants. Note that the border isn't set on the viewport directly, JViewport doesn't support the JComponent border property. Similarly setting the JScrollPane s viewport doesn't affect the viewportBorder property. The default value of this property is computed by the look and feel implementation.

Used by ScrollPaneUI implementations to create the horizontal scrollbar. This is usually unnecessary, as JScrollPane creates horizontal and vertical scrollbars by default. Used by ScrollPaneUI implementations to create the vertical scrollbar. This is usually unnecessary, as JScrollPane creates vertical and horizontal scrollbars by default. Subclasses may override this method to return a subclass of JViewport. Returns: the viewport property See Also: setViewport javax.

Active Oldest Votes. This image is self-explainatory The JViewport provides a window, or "viewport" onto a data source -- for example, a text file. Improve this answer. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta.



0コメント

  • 1000 / 1000