How to enable a scrollbar in a JPanel
Hi
I am adding some components in a JPanel and I am adding the JPanel to a JScrollPane.The JScrollPane is finally added to the container.Now I am manage to get only scrollbars(implicity added) but no nobs.How should I use the scrollbars to view all the components that are added inside the JPanel.
senthil
have u set ur scroll pane like this
splitScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
splitScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
and what lay out ur using for panel,if it is null/Absolute lay out , you will get this problem
b_babu at 2007-6-29 10:20:49 >

Hi babuThanx for ur reply.I had given the two scrollbars in the constructor of the JScrollPane itself.I haven't set any layout for that panel so it is using the Default Layout.Will it work?
senthil it should work , but anyway try this alsopanel.setAutoscrolls(true);hope it will workbye
b_babu at 2007-6-29 10:20:49 >

I've gotten JScrollPanes to work with Null Layout Panels, you just have to set the Preferred Size of the Panel.
Yes boss , u are absolutely correct.It is working fine.
b_babu at 2007-6-29 10:20:49 >

Hi all
Here is my code.
//code here
pnlCommands = new JPanel();
pnlCommands.setLayout(new FlowLayout());
pnlCommands.setPreferredSize(new Dimension(190,300));
pnlCommands.setBackground(Color.white);
pnlCommands.setAutoscrolls(true);
scrCommands = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrCommands.setViewportView(pnlCommands);
//here I add some components to the panel
pnlCommands.add(new JButton("Start");
.
.
.
.
.
.
.
.
.
.
pnlCommands.add(new JButton("End");
I tried with ur idea but only the vertical scrollbar is visible with no nobs.And only half components is visible to me.what should i want to do next?
regards
senthil
Hello anybody is there to solve this problem
You didnt actually "add" the jpanel to the scroll pane did you? You actually did something more like this right?jScrollPane1.getViewport().add(jTextPane1, null);
dnoyeB at 2007-6-29 10:20:49 >

HiI had tried that also but still it is not coming.After adding all the components to that panel.I will add the scrollPane to another panel.Finally that JPanel is added to the container.
Hi,I thought you wanted scrollbars (horizontal and vertical). Why then do you say "ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER"? If you want the horizontal scrollbar too, then you have to say ALWAYS.Regards,Olaf
> Hi,
>
> I thought you wanted scrollbars (horizontal and
> vertical). Why then do you say
> "ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER"? If
> you want the horizontal scrollbar too, then you have
> to say ALWAYS.
>
> Regards,
> Olaf
Yes...what he said.
dnoyeB at 2007-6-29 10:20:49 >
