How to include the vertical scrollbar in Jpanel with spring layout

How to include the scrollbar in jpanel with spring layout.I have included the jpanel.

Here is my code.

Jpanel panel = new Jpanel(new sprngLayout())
JScrollpane spane = new JScrollpane(panel);
spane.add(a);
spane.add(b);
continer.add(spane);

Please help me.
Rose_TaylorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
try:

Jpanel panel = new Jpanel(new sprngLayout())
JScrollpane spane = new JScrollpane(panel);
panel.add(a);
panel.add(b);
continer.add(spane);
0
Rose_TaylorAuthor Commented:
I have using four panels.like one outerpanel within outerpanel there two innerpanel,here i need only one panel need scrollbar.I am not sure why this is happing in my code.

Example:
outPaneel
...
...
new innerpanel
....
....
Jpanel panel = new Jpanel(new sprngLayout())
JScrollpane spane = new JScrollpane(panel);
panel.add(a);
panel.add(b);
outerpanel.add(innerpanel1);
outerpanel.add(spane);
continer.add(outerpanel);

0
objectsCommented:
> I am not sure why this is happing in my code.

not sure what is happening?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Rose_TaylorAuthor Commented:
:) I am not getting vertical scrollbar on my window.Please let me...
0
objectsCommented:
is the panel large enough to need one?

see here to force scrollbars
http://helpdesk.objects.com.au/java/how-do-i-get-a-jscrollpane-to-always-display-scroll-bars
0
Rose_TaylorAuthor Commented:
Excellent , I am getting scrollbar.But it is not enabled...looks like disabled.Rows are extend to the panel, but scrollbar not active.
0
objectsCommented:
sounds like a problem with your panel. check it is returning the correct preferred size
0
Rose_TaylorAuthor Commented:
Please give me any suggestions on this issue.
0
objectsCommented:
need to see the relevant parts of your code to be able to help further
0
Rose_TaylorAuthor Commented:
Please look at this......
JPanel packingPanel = new JPanel(new FlowLayout());
	        packingPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.white),"pack"));
	        packingPanel.setBackground(EZschool.getApplicationBGColor());
	        packingPanel.setPreferredSize(new Dimension(400, 200));
	        JScrollPane scrollPane = new JScrollPane(packingPanel);
	       // scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
	        		scrollPane.setVerticalScrollBarPolicy(
	        		JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 
	         
			packingJRadioButton1 = new JRadioButton("TV)");
			packingJRadioButton1.setSelected(true);
			packingbuttongroup = new ButtonGroup();
			packingbuttongroup.add(packingJRadioButton1);
			packingPanel.add(packingJRadioButton1);
			
			
			packingJRadioButton2 = new JRadioButton("Newspaper");
			packingbuttongroup.add(packingJRadioButton2);
			packingPanel.add(packingJRadioButton2);
			
			
			packingJRadioButton3 = new JRadioButton("Email");
			packingbuttongroup.add(packingJRadioButton3);
			packingPanel.add(packingJRadioButton3);
			
			
			packingJRadioButton4 = new JRadioButton("Mail");
			packingbuttongroup.add(packingJRadioButton4);
			packingPanel.add(packingJRadioButton4);
			
			packingJRadioButton5 = new JRadioButton("Open-Portrait");
			packingbuttongroup.add(packingJRadioButton5);
			packingPanel.add(packingJRadioButton5);
			
			packingJRadioButton6 = new JRadioButton("Closed-Portrait");
			packingbuttongroup.add(packingJRadioButton6);
			packingPanel.add(packingJRadioButton6);
			
			packingJRadioButton7 = new JRadioButton("Open-Sports");
			packingbuttongroup.add(packingJRadioButton7);
			//packingPanel.add(packingJRadioButton7);
			
			


			
			  mountPanel.setLayout(new BoxLayout(mountPanel, BoxLayout.Y_AXIS));			  
			  packingPanel.setLayout(new BoxLayout(packingPanel, BoxLayout.Y_AXIS));
			  //jscrollPane.setLayout(new BoxLayout(jscrollPane, BoxLayout.Y_AXIS));
			  
	       
	        servicePanel.add(scrollPane);

Open in new window

0
objectsCommented:
>                 packingPanel.setPreferredSize(new Dimension(400, 200));

try getting rid of that

and why do you change the layout of packingPanel?
0
objectsCommented:
How did that go?
0
Rose_TaylorAuthor Commented:
No ...still i didn't get scrollbar...
0
objectsCommented:
your code works fine when I tested it
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;

public class GUI {

	public static void main(String[] args) {

		JFrame frame = new JFrame();
		JPanel packingPanel = new JPanel(new FlowLayout());
		packingPanel.setBorder(BorderFactory.createTitledBorder(
				BorderFactory.createLineBorder(Color.white), "pack"));
		packingPanel.setBackground(Color.red);
		packingPanel.setPreferredSize(new Dimension(400, 200));
		JScrollPane scrollPane = new JScrollPane(packingPanel);
		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

		JRadioButton packingJRadioButton1 = new JRadioButton("TV)");
		packingJRadioButton1.setSelected(true);
		ButtonGroup packingbuttongroup = new ButtonGroup();
		packingbuttongroup.add(packingJRadioButton1);
		packingPanel.add(packingJRadioButton1);

		JRadioButton packingJRadioButton2 = new JRadioButton("Newspaper");
		packingbuttongroup.add(packingJRadioButton2);
		packingPanel.add(packingJRadioButton2);

		JRadioButton packingJRadioButton3 = new JRadioButton("Email");
		packingbuttongroup.add(packingJRadioButton3);
		packingPanel.add(packingJRadioButton3);

		JRadioButton packingJRadioButton4 = new JRadioButton("Mail");
		packingbuttongroup.add(packingJRadioButton4);
		packingPanel.add(packingJRadioButton4);

		JRadioButton packingJRadioButton5 = new JRadioButton("Open-Portrait");
		packingbuttongroup.add(packingJRadioButton5);
		packingPanel.add(packingJRadioButton5);

		JRadioButton packingJRadioButton6 = new JRadioButton("Closed-Portrait");
		packingbuttongroup.add(packingJRadioButton6);
		packingPanel.add(packingJRadioButton6);

		JRadioButton packingJRadioButton7 = new JRadioButton("Open-Sports");
		packingbuttongroup.add(packingJRadioButton7);

		packingPanel.setLayout(new BoxLayout(packingPanel, BoxLayout.Y_AXIS));

		frame.getContentPane().add(scrollPane);
		frame.setSize(100, 100);
		frame.setVisible(true);
	}

}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rose_TaylorAuthor Commented:
Excellent,Thank you .
0
Rose_TaylorAuthor Commented:
Excellent
0
objectsCommented:
no worries
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.