Sei sulla pagina 1di 16

http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.

html

How to Use Scroll Panes


A JScrollPane provides a scrollable view of a component. When screen real estate is limited, use a scroll pane to display a component that is large or one whose size can change dynamically. Other containers used to save screen space include split panes and tabbed panes. The code to create a scroll pane can be minimal. For example, here s a picture of a demo program that puts a text area in a scroll pane because the text area s size grows dynamically as text is appended to it!

"ere s the code that creates the text area, ma#es it the scroll pane s client, and adds the scroll pane to a container!
//In a container that uses a BorderLayout: textArea = new JTextArea(5, 30); ... JScrollPane scrollPane = new JScrollPane(textArea); ... setPreferredSize(new Di ension(!50, ""0)); ... add(scrollPane, #order$a%o&t.'()T(*);

The boldface line of code creates the JScrollPane, specifying the text area as the scroll pane s client. The program doesn t invo#e any methods on the JScrollPane ob$ect, since the scroll pane handles everything automatically! creating the scroll bars when necessary, redrawing the client when the user moves the scroll #nobs, and so on. %ou might have noticed that the preceding code sets the preferred size of the scroll pane s container. &n the 'ava loo# and feel, this preferred size happens to be a bit less tall than re(uired for the text area to display the ) rows that we re(uested when creating it, so the scroll bar initially displays a vertical scroll bar. &f we didn t restrict the size of the scroll pane s container, the scroll pane would be big enough for the text area to display the full ) rows and *+ columns specified with the JTextArea

constructor. ,efer to -izing a -croll .ane for information about techni(ues for ma#ing a scroll pane the size you want. The rest of this section discusses the following topics!

"ow a -croll .ane Wor#s -etting the -croll /ar .olicy .roviding 0ustom 1ecorations &mplementing a -crolling2-avvy 0lient -izing a -croll .ane 1ynamically 0hanging the 0lient s -ize The -croll .ane A.& 3xamples that 4se -croll .anes

How a Scroll Pane Works


"ere is a snapshot of an application that uses a customized scroll pane to view a photograph!

The scroll pane in this application loo#s very different from the one in the previous demo program. ,ather than displaying text, this scroll pane contains a image. The scroll pane also has two scroll bars, a row header, a column header, and four corners, three of which have been customized. Try this:: 5. 0lic# the 6aunch button to run -croll1emo using 'ava7 Web -tart 8download '19 : or later;. Alternatively, to compile and run the example yourself, consult the example index.

<. =ove the #nobs on the scroll bars. Watch the image scroll and the horizontal and vertical rulers scroll along. *. &f you have a mouse with a wheel 8which is generally between the mouse buttons; use the mouse wheel to scroll the image vertically. >. 0lic# the cm toggle in the upper left corner of the scroll pane. The units on the row and column headers change to inches 8or bac# to centimeters;. ). 0lic# the arrow buttons on the scroll bars. Also, try clic#ing on the trac# above or below the #nob on the vertical scroll bar, or to the left or right of the horizontal one. :. =ove the cursor over the image and press the cursor. 0ontinuing to press the cursor, drag to a point outside the image and pause. The visible area of the image moves toward the cursor. This scroll2by2dragging functionality is enabled by the scroll pane, and with the J'o +onent A.&, but it is implemented by the custom component that displays the image. ?. ,esize the window. @otice that the scroll bars disappear when the scroll pane is large enough to display the entire image and reappear again when the scroll pane is too small to show the entire image.

The -croll1emo program establishes the scroll pane s client when creating the scroll pane!
,,Where the member variables are declared: +ri-ate Scrolla.lePict&re +ict&re; ... ,,Where the GUI is created: +ict&re = new Scrolla.lePict&re( ... ); JScrollPane +ict&reScrollPane = new JScrollPane(+ict&re);

The scroll pane s client is also #nown as the view or viewport view. %ou can change the client dynamically by calling the set/iew+ort/iew method. @ote that JScrollPane has no corresponding 0et/iew+ort/iew method. &f you need to refer to the client ob$ect again, you can either cache it in a variable or invo#e 0et/iew+ort().0et/iew+ort/iew() on the scroll pane. When the user manipulates the scroll bars in a scroll pane, the area of the client that is visible changes accordingly. This picture shows the relationship between the scroll pane and its client and indicates the classes that the scroll pane commissions to help!

A scroll pane uses a J/iew+ort instance to manage the visible area of the client. The viewport is responsible for positioning and sizing the client, based on the positions of the scroll bars, and displaying it. A scroll pane may use two separate instances of JScroll#ar for the scroll bars. The scroll bars provide the interface for the user to manipulate the visible area. The following figure shows the three areas of a scroll bar! the #nob 8sometimes called the thumb;, the 8arrow; buttons, and the trac#.

When the user moves the #nob on the vertical scroll bar up and down, the visible area of the client moves up and down. -imilarly, when the user moves the #nob on the horizontal scroll bar to the right and left, the visible area of the client moves bac# and forth accordingly. The position of the #nob relative to its trac# is proportionally e(ual to the position of the visible area relative to the client. &n the 'ava loo# and feel

and some others, the size of the #nob gives a visual clue as to how much of the client is visible. /y clic#ing a arrow button, the user can scroll by a unit increment. /y clic#ing within the trac#, the user can scroll by a block increment. &f the user has a mouse with a wheel, then the user can scroll vertically using the mouse wheel. The amount that the mouse wheel scrolls is platform dependent. For example, by default on Windows A., the mouse wheel scrolls three unit incrementsB the =ouse control panel allows you to specify a different number of unit increments or to use a bloc# increment instead. =ore information about unit and bloc# increments is in &mplementing a -crolling2-avvy 0lient. Typical programs don t directly instantiate or call methods on a viewport or scroll bar. &nstead, programs achieve their scrolling behavior using the JScrollPane A.& and the A.& discussed in &mplementing a -crolling2-avvy 0lient. -ome scrolling2 savvy components such as J$ist, JTa.le, and JTree also provide additional A.& to help you affect their scrolling behavior.

Setting the Scroll ar Policy


On startup, the scroll pane in the ScrollDe o application has two scroll bars. &f you ma#e the window large, both scroll bars disappear because they are no longer needed. &f you then shrin# the height of the window without changing its width, the vertical scroll bar reappears. Further experimentation will show that in this application both scroll bars disappear and reappear as needed. This behavior is controlled by the scroll pane s scroll bar policy, Actually, it s two policies! each scroll bar has its own. doesn t explicitly set the scroll pane s scroll bar policies C it uses the default. %ou can set the policies when you create the scroll pane or change them dynamically.
ScrollDe o

Of the constructors provided by JScrollPane, these two let you set the scroll bar policies when you create the scroll pane!
JScrollPane('o +onent, int, int) JScrollPane(int, int)

The first int specifies the policy for the vertical scroll barB the second specifies the policy for the horizontal scroll bar. %ou can also set the policies dynamically with the set1orizontalScroll#arPolic% and set/erticalScroll#arPolic% methods. With both the constructors and the methods, use one of the following constants defined in the ScrollPane'onstants interface 8which is implemented by JScrollPane;! Policy
/(*T2'A$3S'*4$$#A*3AS3)((D(D 14*254)TA$3S'*4$$#A*3AS3)((D(D

!escription The default. The scroll bar appears when the

/(*T2'A$3S'*4$$#A*3A$6A7S 14*254)TA$3S'*4$$#A*3A$6A7S /(*T2'A$3S'*4$$#A*3)(/(* 14*254)TA$3S'*4$$#A*3)(/(*

viewport is smaller than the client and disappears when the viewport is larger than the client. Always display the scroll bar. The #nob disappears if the viewport is large enough to show the whole client. @ever display the scroll bar. 4se this option if you don t want the user to directly control what part of the client is shown, or if you want them to use only non2scroll2bar techni(ues 8such as dragging;.

Providing "ustom !ecorations


The area drawn by a scroll pane consists of up to nine parts! the center, four sides, and four corners. The center is the only component that is always present in all scroll panes. /esides scroll bars, the sides can contain column and row headers. A corner component is visible only if both sides that intersect at that corner contain visible components.

As shown in the figure, the scroll pane in ScrollDe o has custom row and column headers. Additionally, because all four sides are populated, all four corners are present. The program customizes three of the corners C two $ust fill their area with the same color as the *&les, and the other contains a toggle button. The fourth corner, the lower right corner, is the default provided by the scroll pane. @otice that because the row and column headers are always present in this example, the toggle button is also always present. &f a corner contains a control that the user needs access to all the time, ma#e sure the sides that intersect at the corner are always present. For example, if this application

placed the toggle in the lower right corner where the scroll bars intersect, then the toggle would disappear if the user resized the window and even one of the scroll bars disappeared. The scroll pane s row and column headers are provided by a custom J'o +onent subclass, *&le, that draws a ruler in centimeters or inches. "ere s the code that creates and sets the scroll pane s row and column headers!
//Where the member variables are defined: +ri-ate *&le col& n/iew; +ri-ate *&le row/iew; ... //Where the GUI is initialized: 2 a0e2con .ee = create2 a0e2con(8i a0es,fl%in0#ee.9+08); ... ,,'reate t:e row and col& n :eaders. col& n/iew = new *&le(*&le.14*254)TA$, tr&e); row/iew = new *&le(*&le./(*T2'A$, tr&e); ... pictureScrollPane.setColumnHeaderView(columnView); pictureScrollPane.setRowHeaderView(rowView);

%ou can use any component for a scroll pane s row and column headers. The scroll pane puts the row and column headers in J/iewPorts of their own. Thus, when scrolling horizontally, the column header follows along, and when scrolling vertically, the row header follows along. =a#e sure the row and column have the same width and height as the view, because '-croll.ane does not enforce these values to have the same size. &f one differs from the other, you are li#ely to not get the desired behavior. As a J'o +onent subclass, our custom *&le class puts its rendering code in its +aint'o +onent method. The *&le rendering code ta#es care to draw only within the current clipping bounds, to ensure speedy scrolling. %our custom row and column headers should do the same. %ou can also use any component for the corners of a scroll pane. ScrollDe o illustrates this by putting a toggle button in the upper left corner, and custom 'orner ob$ects in the upper right and lower left corners. "ere s the code that creates the 'orner ob$ects and calls set'orner to place them!
,,'reate t:e corners. JPanel .&tton'orner = new JPanel(); ,,&se ;low$a%o&t is<etric = new JTo00le#&tton(8c 8, tr&e); is<etric.set;ont(new ;ont(8SansSerif8, ;ont.P$A2), "")); is<etric.set<ar0in(new 2nsets(=,=,=,=)); is<etric.add2te $istener(t:is); .&tton'orner.add(is<etric); ... ,,Set t:e corners. pictureScrollPane.setCorner(JScrollPane.UPP R!" #$!C%R& R' (uttonCorner);

pictureScrollPane.setCorner(JScrollPane."%) R!" #$!C%R& R' new Corner()); pictureScrollPane.setCorner(JScrollPane.UPP R!R*+H$!C%R& R' new Corner());

,emember that the size of each corner is determined by the size of the sides intersecting there. For some components you must ta#e care that the specific instance of the component fits in its corner. For example, the program sets the font and margins on the toggle button so that it fits within the space established by the headers. &t s not an issue with the 'orner class because that class colors its entire bounds, whatever they happen to be, with a solid color. As you can see from the code, constants indicate the corner positions. This figure shows the constant for each position!

The constants are defined in the ScrollPane'onstants interface, which JScrollPane implements.

#mplementing a Scrolling$Savvy "lient


To customize the way that a client component interacts with its scroll pane, you can ma#e the component implement the Scrolla.le interface. /y implementing Scrolla.le, a client can specify both the size of the viewport used to view it and the amount to scroll for clic#s on the different controls on a scroll bar. %ou can also specify if the view should trac# the size of the viewport. This is typically used when the viewport is bigger than the view, but the view should fill the available space. %ote: &f you can t or don t want to implement a scrollable client, you can specify the unit and bloc# increments using the set>nit2ncre ent and set#loc?2ncre ent methods of JScroll#ar. For example, the following code sets the unit increment for vertical scrolling to 5+ pixels!
scrollPane.0et/erticalScroll#ar().set>nit2ncre ent("0);

"ere again are the three control areas of a scroll bar! the #nob, the buttons, and the trac#.

%ou might have noticed when manipulating the scroll bars in ScrollDe o that clic#ing the buttons scrolls the image to a tic# boundary. %ou might also have noticed that clic#ing in the trac# scrolls the picture by a DscreenfulD. =ore generally, the button scrolls the visible area by a unit increment and the trac# scrolls the visible area by a bloc# increment. The behavior you see in the example is not the scroll pane s default behavior, but is specified by the client in its implementation of the Scrolla.le interface. The client for the ScrollDe o program is Scrolla.lePict&re. Scrolla.lePict&re is a subclass of J$a.el that provides implementations of all five Scrolla.le methods!
0etScrolla.le#loc?2ncre ent 0etScrolla.le>nit2ncre ent 0etPreferredScrolla.le/iew+ortSize 0etScrolla.leTrac?s/iew+ort1ei0:t 0etScrolla.leTrac?s/iew+ort6idt:

implements the Scrolla.le interface primarily to affect the unit and bloc# increments. "owever, it must provide implementations for all five methods. Thus, it provides reasonable defaults for the other three methods that you might want to copy for your scrolling2savvy classes.
Scrolla.lePict&re

The scroll pane calls the client s 0etScrolla.le>nit2ncre ent method whenever the user clic#s one of the buttons on the scroll bar. This is true as long as the client implements -crollable. This method returns the number of pixels to scroll. An obvious implementation of this method returns the number of pixels between tic# mar#s on the header rulers. Scrolla.lePict&re, however, does something different! &t returns the value re(uired to position the image on a tic# mar# boundary. "ere s the implementation!
+&.lic int 0etScrolla.le>nit2ncre ent(*ectan0le -isi.le*ect, int orientation, int direction) @ ,,Aet t:e c&rrent +osition. int c&rrentPosition = 0; if (orientation == Swin0'onstants.14*254)TA$) @ c&rrentPosition = -isi.le*ect.x; B else @ c&rrentPosition = -isi.le*ect.%; B

,,*et&rn t:e n& .er of +ixels .etween c&rrentPosition ,,and t:e nearest tic? ar? in t:e indicated direction. if (direction C 0) @ int newPosition = c&rrentPosition D (c&rrentPosition , ax>nit2ncre ent) E ax>nit2ncre ent; ret&rn (newPosition == 0) F ax>nit2ncre ent G newPosition; B else @ ret&rn ((c&rrentPosition , ax>nit2ncre ent) H ") E ax>nit2ncre ent D c&rrentPosition; B B

&f the image is already on a tic# mar# boundary, this method returns the number of pixels between tic#s. Otherwise, it returns the number of pixels from the current location to the nearest tic#. 6i#ewise, the scroll pane calls the client s 0etScrolla.le#loc?2ncre ent method each time the user clic#s on the trac#, but only if the client implements -crollable. "ere s Scrolla.lePict&re s implementation of this method!
+&.lic int 0etScrolla.le#loc?2ncre ent(*ectan0le -isi.le*ect, int orientation, int direction) @ if (orientation == Swin0'onstants.14*254)TA$) ret&rn -isi.le*ect.widt: D ax>nit2ncre ent; else ret&rn -isi.le*ect.:ei0:t D ax>nit2ncre ent; B

This method returns the height of the visible rectangle minus a tic# mar#. This behavior is typical, but true if scrolling vertically, otherwise, it s the width.A bloc# 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 8depending on the scroll direction;.
Scrolla.lePict&re.9a-a has one more bit of code that s not re(uired by the Scrolla.le interface, but is common in scrollable components! a mouse motion

listener that lets the user scroll the picture by dragging from it. The boldface code in the following snippet implements scrolling by dragging!
+&.lic class Scrolla.lePict&re extends J$a.el i +le ents Scrolla.le, ,ouse,otion"istener @ ... +&.lic Scrolla.lePict&re(...) @ ... setAutoscrolls(true); ,,ena.le s%nt:etic dra0 e-ents add,ouse,otion"istener(t-is); ,,:andle o&se dra0s B ...

pu(lic .oid mouse/ra00ed(,ouse .ent e) 1 ,,T:e &ser is dra00in0 &s, so scrollI Rectan0le r = new Rectan0le(e.0et2()' e.0et3()' 4' 4); scrollRect$oVisi(le(r); 5 ... B

This snippet scrolls the picture whenever the user drags from the picture to a location outside the picture and pauses. The setA&toscrolls method is defined by J'o +onent for the purpose of assisting C but not implementing C scrolling by dragging. -etting the autoscrolls property to tr&e ma#es the component fire synthetic mouse2dragged events even when the mouse isn t moving 8because it stopped, mid2drag, outside the component;. &t s up to the component s mouse motion listener to listen for these events and react accordingly.

Si&ing a Scroll Pane


4nless you explicitly set a scroll pane s preferred size, the scroll pane computes it based on the preferred size of its nine components 8the 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. &f the client is not scrolling2savvy, then the scroll pane sizes itself so that the client displays at its preferred size. For typical unsavvy clients, this ma#es 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. &n 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. &f the client is scrolling2savvy, then the scroll pane uses the value returned by the client s 0etPreferredScrolla.le/iew+ortSize method to compute the size of its viewport. &mplementations 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 J$ist s implementation of 0etPreferredScrolla.le/iew+ortSize is $ust big enough to display eight rows. -crolling2savvy classes, li#e lists, tables, text components, and trees, often provide one or more methods that let programmers affect the size returned from 0etPreferredScrolla.le/iew+ortSize. For example, you can set the number of visible rows in a list or a tree by calling the set/isi.le*ow'o&nt method. The list or tree ta#es care of figuring out the size needed to display that number of rows. ,efer to =ethods in Other 0lasses ,elated to -crolling for information about scrolling2related methods provided by classes other than JScrollPane. And remember C if you don t li#e the value that 0etPreferredScrolla.le/iew+ortSize returns, you can always set the preferred size of the scroll pane or its container.

!ynamically "hanging the "lient's Si&e


0hanging the size of a scroll pane s client is a two2step process. First, set the client s preferred size. Then, call re-alidate on the client to let the scroll pane #now that it should update itself and its scroll bars. 6et s loo# at an example. "ere 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!

%ou can find the full source code for this example in ScrollDe o=.9a-a, which is based on an example provided by tutorial reader 'ohn Eella. %ou can run Scroll!emo( 8 download '19 : or later;. "ere s the code that changes the drawing area s size when necessary!
if (c:an0ed) @ ,,>+date clientJs +referred size .eca&se ,,t:e area ta?en &+ .% t:e 0ra+:ics :as ,,0otten lar0er or s aller (if cleared). drawin0Area.setPreferredSize(/* the new size */); ,,$et t:e scroll +ane ?now to &+date itself ,,and its scroll .ars. drawin0Area.re-alidate();

@ote that when the client changes size, the scroll bars ad$ust. The scroll pane doesn t resize, nor does the viewport. ,efer to S+litPaneDe o for another example in which the client ob$ect changes size.

The Scroll Pane )P#

The following tables list the commonly used scroll2related constructors and methods. Other methods you are most li#ely to invo#e on a JScrollPane ob$ect are those such as setPreferredSize that its superclasses provide. -ee The '0omponent A.& for tables of commonly used inherited methods. The A.& for using scroll panes falls into these categories!

-etting 4p the -croll .ane 1ecorating the -croll .ane &mplementing a -crolling2-avvy 0lient =ethods in Other 0lasses ,elated to -crolling -etting 4p the -croll .ane 8JScrollPane constructors and methods;

*ethod or "onstructor '-croll.ane8; '-croll.ane80omponent; '-croll.ane8int, int; '-croll.ane80omponent, int, int;


-oid set/iew+ort/iew('o +onent)

Purpose 0reate a scroll pane. The 'o +onent parameter, when present, sets the scroll pane s client. The two int parameters, when present, set the vertical and horizontal scroll bar policies 8respectively;. -et the scroll pane s client.

-et or get the vertical scroll policy. ScrollPane'onstants defines three values -oid set/erticalScroll#arPolic%(int) for specifying this policy! int /(*T2'A$3S'*4$$#A*3AS3)((D(D 8the 0et/erticalScroll#arPolic%() default;, /(*T2'A$3S'*4$$#A*3A$6A7S, and /(*T2'A$3S'*4$$#A*3)(/(*. -et or get the horizontal scroll policy. ScrollPane'onstants defines three values void set"orizontal-croll/ar.olicy8int; for specifying this policy! 14*254)TA$3S'*4$$#A*3AS3)((D(D 8the int get"orizontal-croll/ar.olicy8; default;, 14*254)TA$3S'*4$$#A*3A$6A7S, and 14*254)TA$3S'*4$$#A*3)(/(*. void setEiewport/order8/order; /order getEiewport/order8; boolean isWheel-crolling3nabled8; -et or get the border around the viewport.This is preferred over setting the border on the component. -et or get whether scrolling occurs in response to the mouse wheel. =ouse2wheel scrolling is enabled by default.

1ecorating the -croll .ane 8JScrollPane methods; *ethod Purpose void -et the column or row header for the scroll set0olumn"eaderEiew80omponent; pane.

void set,ow"eaderEiew80omponent; -et or get the corner specified. The int parameter specifies which corner and must be one of the following constants defined in ScrollPane'onstants! >PP(*3$(;T3'4*)(*, >PP(*3*2A1T3'4*)(*, $46(*3$(;T3'4*)(*, $46(*3*2A1T3'4*)(*, $46(*3$(AD2)A3'4*)(*, $46(*3T*A2$2)A3'4*)(*, >PP(*3$(AD2)A3'4*)(*, and >PP(*3T*A2$2)A3'4*)(*. Purpose

void set0orner8-tring, 0omponent; 0omponent get0orner8-tring;

&mplementing a -crolling2-avvy 0lient *ethod Fet the unit or bloc# increment in pixels. The *ectan0le parameter is the bounds of the currently visible rectangle. The first int int get-crollable4nit&ncrement8,ectangle, parameter is either int, int; Swin0'onstants.14*254)TA$ or int Swin0'onstants./(*T2'A$ depending on get-crollable/loc#&ncrement8,ectangle, what scroll bar the user clic#ed on. The int, int; second int parameter indicates which (required by the crollable interface) direction to scroll. A value less than + indicates up or left. A value greater than + indicates down or right. 1imension get.referred-crollableEiewport-ize8; (required by the crollable interface) boolean get-crollableTrac#sEiewportWidth8; boolean get-crollableTrac#sEiewport"eight8; (required by the crollable interface) Fet the preferred size of the viewport. This allows the client to influence the size of the viewport in which it is displayed. &f the viewport size is unimportant, implement this method to return 0etPreferredSize. Fet whether the scroll pane should force the client to be the same width or height as the viewport. A return value of tr&e from either of these methods effectively disallows horizontal or vertical scrolling 8respectively;. -et whether synthetic mouse dragged events should be generated when the user drags the mouse outside of the component and stopsB these events are necessary for scrolling by dragging. /y default, the value is false, but many scrollable components such as JTa.le and custom components set the value to tr&e.

void setAutoscrolls8boolean; (in !"om#onent)

=ethods in Other 0lasses ,elated to -crolling

*ethod void scroll,ectToEisible8,ectangle; (in !"om#onent)

Purpose &f 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. -et or get how many rows of the list are visible. The compute its return value. -croll so that the row at the specified index is visible. This method calls scroll*ectTo/isi.le and wor#s only if the list is in a container, such as a scroll pane, that supports scrolling. -et or get how many rows of the tree are visible. The
0etPreferredScrolla.le/iew+ortSi ze method uses the visible row count to

void setEisible,ow0ount8int; int getEisible,ow0ount8; (in !List)

0etPreferredScrolla.le/iew+ortSi ze method uses the visible row count to

void ensure&ndex&sEisible8int; (in !List)

void setEisible,ow0ount8int; int getEisible,ow0ount8; (in !$ree)

compute its return value. -croll so that the specified tree path or row at the specified index is visible. These methods call scroll*ectTo/isi.le and wor# only if the tree is in a container, such as a scroll pane, that supports scrolling. -et or get whether scrolling occurs automatically when the user expands a node. True by default. This feature wor#s only when the tree is in a container, such as a scroll pane, that supports scrolling.

void scroll.athToEisible8Tree.ath; void scroll,owToEisible8int; (in !$ree)

void set-crollsOn3xpand8boolean; boolean get-crollsOn3xpand8; (in !$ree)

void the value to be returned by set.referred-crollableEiewport-ize81imensi -et 0etPreferredScrolla.le/iew+ortSi on; ze. (in !$able)

+,amples that Use Scroll Panes


This table shows the examples that use JScrollPane and where those examples are described. +,ample Where !escri-ed %otes

This section, "ow to 4se Tool -hows a simple, yet typical, use of a scroll pane. /ars ScrollDe o This section 4ses many of scroll pane s bells and whistles. ScrollDe o= This section -hows how to change the client s size. "ow to 4se -plit .uts a list and a label in a scroll pane. Also, .anes, S+litPaneDe o shows how to handle the case when a scroll "ow to 4se pane s client changes size. 6ists "ow to 4se Ta.leDe o .uts a table in a scroll pane. Tables 4sing Text .uts a text area, an editor pane, and a text pane TextSa +lerDe o 0omponents each in a scroll pane. "ow to 4se TreeDe o .uts a tree in a scroll pane. Trees
Tool#arDe o

Potrebbero piacerti anche