aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Manually sizing JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Manually sizing JScrollPane" Watch "Manually sizing JScrollPane" New topic
Author

Manually sizing JScrollPane

Andrew Cho
Ranch Hand

Joined: Jun 29, 2011
Posts: 50
Hey all,

I am working on a GUI, and in it is a JScrollPane. In the ScrollPane is a JPanel that holds multiple JTextPanes. That way there will be multiple viewable TextPanes in one scrollpane. However I want the scrollpane to not show all of the Panel that it contains; I want it to be a smaller size. I have tried putting the scrollpane in another panel, which goes in my applet, but the panel resizes because it is in a layout manager. How would I be able to make the size of the viewport set to what I want it to be?

Thanks for any help,

Andrew
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

You're not going to like my answer. By using an appropriate layout manager, or a combination of layout managers, possibly in conjunction with EmptyBorders.

To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

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

Joined: Jun 29, 2011
Posts: 50
Ok thanks Darryl,
Heres an example of what I'm talking about


Thanks for your help,
Andrew
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

An applet is never an SSCCE, as I need an HTML page to be able to display it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
An applet is never an SSCCE, as I need an HTML page to be able to display it.


I also agree with this.

I'm not sure how IDE's work, but when using the command line there is a simple solution provided the poster adds the following as the first line to the posted source code:



Now from the command line you can do the following:

javac TestApplet2.java
appletviewer TestApplet2.java

However, I agree the safest way to post code is to post an application as many people will not go to the trouble of testing applets.

Anyway, back to the question. As mentioned by Darryl its a matter of understanding how layout managers work. You set the preferred size of the wrong component:



Andrew Cho
Ranch Hand

Joined: Jun 29, 2011
Posts: 50
Yeah sorry about posting an applet instead of an application. While i was making the application however, I put in the code from Rob, and I got it to work.

Thanks guys,
Andrew
 
 
subject: Manually sizing JScrollPane