File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Adding JScollPane into JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding JScollPane into JPanel" Watch "Adding JScollPane into JPanel" New topic
Author

Adding JScollPane into JPanel

uttam kumar
Ranch Hand

Joined: Jan 27, 2009
Posts: 128

Hi,

We have an existing swing application and I have to customize its one of screen. The screen is divided into several parts and each part is being declared as a JPanel. I have to show a file into a particular area which would be scrollable. So now the problem is that I have to add scrolling into the existing JPanel. I tried adding JScrollPane to JPanel but didnt succeed. I read that we have to add JPanel into JScrollPane to achieve the desired result but in my case its not possible. I dont have much idea about swing. Can anyone help me out of this?
Thanks in advance.

Regards,
Uttam Kumar
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

If you want to add scrolling possibilities to a JPanel you need to add the JPanel to a JScrollPane, not vice versa. The JPanel's preferred size will determine when the scroll bars are needed and how large they will be.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
uttam kumar
Ranch Hand

Joined: Jan 27, 2009
Posts: 128

Its not possible in my case. Still I have to achieve the thing. Is there any other way to do it ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Why can't you do this? What is preventing you from replacing the JPanel references to JScrollPane references?

Should you really be limited, I see only one option: use another JPanel, add all controls to that instead, add that to the JScrollPane and add the JScrollPane to your JPanel.

So instead of you use this instead: The border layout will ensure that the JScrollPane will fill the entire panel.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2180
    
    7
I have to customize its one of screen.


Then its possible. If you are changing the code you can do anything you want. If you aren't changing the code then you can't customize it.
uttam kumar
Ranch Hand

Joined: Jan 27, 2009
Posts: 128

Hi Rob,

Thanks for your quick response.
I was asking the same thing - how to add a JScrollPane to a JPanel.

I will try your suggestion.

Thanks,
Uttam Kumar
 
Consider Paul's rocket mass heater.
 
subject: Adding JScollPane into JPanel