• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Adding ScrollPane to JPanel

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic