aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes ScrollPane is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ScrollPane is not working" Watch "ScrollPane is not working" New topic
Author

ScrollPane is not working

Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100



I want to have a text area in east of my form with scroll pane.
Above is a code-clip. All is fine but text area is not showing scroll pane.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

The text area should go in the scroll pane. Presently, it's in the panel, which is in the scroll pane.


luck, db
There are no new questions, but there may be new answers.
Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

As far as i know in JScrollPane constructor we have to pass viewport as for Panel.
That is what i have done.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

Instead of explaining why your code is right, when you have already posted it to say it isn't right, I suggest you should take the advice you were given.
Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

I am sorry, i am not ignoring the suggestion and don't mean to say that i am completely right, but instead of adopt the suggestion blindly, i am also interested to know at what point I am wrong so that i can make my concept clear as I am beginner.
And Thank You for Suggestion to You All.
Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

@Darryl Burke Thank you vary much.
It will be so nice of you if you can explain why my code was not working.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

A JScrollPane uses the preferred size of the component in its viewport to determine whether or not to show scrollbars. In your case that component is not the JTextArea but the WestWindow with a preferred size of 330x50. That WestWindow contains the JTextArea without scrollbars because you simply never programmed any to be there. If you would not manually set the preferred size the WestWindow would calculate its preferred size from the JTextArea instead.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

In addition to what Rob said, if the scroll pane's viewport component implements the Scrollable interface, the scroll pane's layout manager honors the viewport component's preferences in respect of the preferred viewport size, tracking the viewport width/height and the scrollable increments.

JTextArea implements Scrollable. JPanel does not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ScrollPane is not working