Hi guys i have a problem with JScrollPane,
Firstly i have 2 custom JPanel's i wanted to add them to a JSplitPane
so i added them to a JScrollPane and then those JSplitPane but the problem is if i drag the divider in splitpane the panel doesnot scroll :'(
Here is how i added the panels(LeftPanel and RightPAnel are my custom JPanels)
and (leftpane and rightpane are JScrollPane objects) and splitpane is JSplitPane object

leftpane=new JScrollPane()
	JViewport viewport = leftpane.getViewport();
        viewport.add(new LeftPanel(us));
        viewport.setPreferredSize(new Dimension(500,350));

rightpanel is also same

splitpane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftpane,rightpane);
	splitpane.setOneTouchExpandable(true);
	splitpane.setDividerLocation(700);
	leftpane.setMinimumSize(new Dimension(500,350));
	rightpane.setMinimumSize(new Dimension(250,350));

then i added the splitpane to contentpane and done setBounds for split pane
Here is how the custom panel looks like

class RightPanel extends JPanel
{
	CalendarPanel cp;
	JLabel contentlabel;
	RightPanel()
	{
		super();
		setLayout(null);
		cp=new CalendarPanel();
		contentlabel=new JLabel("Information about clicked date goes here");
		add(cp);
		add(contentlabel);
		cp.setBounds(10,10,350,200);
		contentlabel.setBounds(10,240,350,250);
	}
}

both left and right panel's are alike so help with this scrolling hav i done wrong somewhere :?: if there is wrong tell me i always like to get educated :)
But the interesting thing is if i add my panel like this it is scrollable :-O

leftpanel=new JPanel();
       leftpanel.add(component1);
       .//remaining components
       .//same with rightpanel
       leftpane=new JScrolPane(leftpanel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
       rightpane=new JScrollPane(rightpanel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      splitpane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftpane,rightpane);

than you in advance
-Tizon

Can you make a SMALL complete program that compiles and executes and demonstrates your problem?

Can you make a SMALL complete program that compiles and executes and demonstrates your problem?

here u go i wrote a sample prog and it's successfully compiled and executed hope this demonstrates my prob i just want scroll bars when i drag the divider if panel full panel is not in view

I was able to get it to add scroll bars by removing the absolute layout stuff:

class RightPanel extends JPanel
{
	JLabel contentlabel;
	RightPanel()
	{
		super();
//		setLayout(null);
		//creating and adding component
		contentlabel=new JLabel("Information about this rightpanel goes here i hav added only one component");
		add(contentlabel);
//		contentlabel.setBounds(10,10,350,200);
	}
}

I was able to get it to add scroll bars by removing the absolute layout stuff:

class RightPanel extends JPanel
{
	JLabel contentlabel;
	RightPanel()
	{
		super();
//		setLayout(null);
		//creating and adding component
		contentlabel=new JLabel("Information about this rightpanel goes here i hav added only one component");
		add(contentlabel);
//		contentlabel.setBounds(10,10,350,200);
	}
}

Thanks for your help removing that setLayout(null) got displayed my scrollbars :) but then my panel doesn't obey my setBounds() in the panel :( have any idea how to fix that.
thanks again
-Tizon

Use a layout manager to control the positioning.

Or if you can find what a layout manager provides that the scroll pane needs/uses and provide it yourself, then you could use a null layout.

Use a layout manager to control the positioning.

Or if you can find what a layout manager provides that the scroll pane needs/uses and provide it yourself, then you could use a null layout.

ya that would solve i hav to use gridbaglayout for my project :yawn:
But i don't really understand why setting layout null would effect scrolling can u explain?
i.e why the scrollpane would use resources from a layout manager :?:

why setting layout null would effect scrolling

It could do something that the ScrollPane needs to have done to the component.
I don't know the internals, I only observed that having a layout manager allowed your code to work the way you wanted. To find out what is going on inside, override all of the methods that can be used by a layout manager and see when they are called and with what values. Compare that with what your code does.

It could do something that the ScrollPane needs to have done to the component.
I don't know the internals, I only observed that having a layout manager allowed your code to work the way you wanted. To find out what is going on inside, override all of the methods that can be used by a layout manager and see when they are called and with what values. Compare that with what your code does.

k we shall leave that over ridding methods of layout manager later ;) for now i got it worked thanks for your help :*
i will work with that layout manger with my project and post the results soon thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.