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.
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.
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.