If u don't want to change the panel's layout, u have get ur task done in indirect way.
Take another Panel [boo], set its Layout to BorderPanel, add ur Panel to boo, & then add boo to ScrollPane. Don't set any layout for ScrollPane. ie.,
JPanel boo = new JPanel() ;
boo.setLayout(new BorderLayout());
panel = new JPanel();
panel.setLayout(null);
panel.setBounds(10,10,400,
panel.setPreferredSize(new
..
boo.add(panel) ;
scrollPane = new JScrollPane(boo);
Most IMP: do setPreferredSize() for ur Panel.
Main Topics
Browse All Topics





by: omomPosted on 2003-02-20 at 13:33:44ID: 7989645
I'm curious as to why you want to set the layout to null.
cy
cy(int policy)
OLLBAR_AS_ NEEDED OLLBAR_NEV ER OLLBAR_ALW AYS
cy()
Also, even if you remove the line
panel.setLayout(null);
it won't scroll because there's only one label in the panel, nothing to scroll through.
So you would have to add more labels (or longer) labels to get the scroll bar
(or set it to always have scroll bars:
setHorizontalScrollBarPoli
public void setHorizontalScrollBarPoli
Determines when the horizontal scrollbar appears in the scrollpane. The options are:
* JScrollPane.HORIZONTAL_SCR
* JScrollPane.HORIZONTAL_SCR
* JScrollPane.HORIZONTAL_SCR
Parameters:
policy - one of the three values listed above
Throws:
IllegalArgumentException - if policy is not one of the legal values shown above
See Also:
getHorizontalScrollBarPoli