Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding ScrollPane to JPanel

 
Nageswar Kakolla
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Does JPanel need to implement Scrollable interface in order to add JScrollPane ?

I wanted to add JScrollPane to JPanel containing array of Radio Buttons.

I tried very hard but in vain

let me post the code what I am trying

JPanel m_itemPanel = new JPanel();
JScrollPane m_scrollPane = new JScrollPane(m_itemPanel);
m_scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_ALWAYS);

since I need to scrollpane to this JPanel and not to JFrame and I cant get getContentPane() of Frame

My JPanel consists of series of JRadioButtons and I want JScrollpane to be visible so that I can scroll down and Up

Appreciate Quick response and Thanx in advance for your help
 
Matti Poro
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You add a component to a JScrollPane, not vice versa. Make sure it is m_scrollpane you added to the container (JFrame) and not m_itempanel.
 
Nageswar Kakolla
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
initially i did add JPanel to JScrollpane but that time

all radiobuttons in JPanel are gone and i havent seen scrollbar either
 
Matti Poro
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an example:


[ March 02, 2006: Message edited by: Matti Poro ]
 
Nageswar Kakolla
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I want to add Scrollpane to JPanel which inturn called by JFrame.

So you are telling me I should add scrollpane to JFrame
 
Matti Poro
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JPanel will be added with the JScrollPane.
 
Nageswar Kakolla
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Matti for your response.

I executed your sample code and put similar logic for my problem

JFrame frame = getRapidFrame(this);
frame.add(new JScrollPane(m_itemPanel));
//frame.setSize(200,200);
frame.setVisible(true);

where getRapidFrame will give JFrame of whole application where My Panel is hosted but behaviour is wiered i got.

Is it possible to add ScrollPane to JPanel instead of Frame ?

I will explain myproject breifly :
I have Frame where it is divided into regions left & right areas where each region is JPanel.
My right area will host JPanels depending on the selection of nodes in left area.

one of My JPanel will come into picture in right region and I have array of radio buttons to be displayed with Scrollpane.

If I tried to get Parent Frame and add Scrollbar,I got wierd display like my radio buttons are scattered all over and there is no scroll bar displayed

I am not able to post GUI screen here to explain ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic