posted 18 years ago
// this.add(new PaintSurface(), BorderLayout.CENTER);
assuming 'this' refers to the frame, or a panel set as a BorderLayout,
your problems are these
you add labelPic to the container
this.add(labelPic);
you also add it to the scrollPane
JScrollPane scroll=new JScrollPane(labelPic, .......
(or, try to add it - it can't be in two places at once)
the scrollpane is then added to the container
this.add(scroll);
because the container is a BorderLayout, if no location is specifed,
BorderLayout.CENTER becomes the default. so, when you add the label, it
is added to CENTER, then you add the scrollpane (which you've tried to
also add the label to) - it also goes to CENTER, knocking the label out.
so you end up with a scrollpane with nothing in it.
this is one of the normal ways to achieve what you want
create a label, with an imageicon
add the label to a panel
add the panel to a scrollpane
add the scrollpane to another panel //optional - can be added to the frame
add the panel(or scrollpane) to the frame/contentPane
for the scrollpane to work properly, it must be smaller than the component
it contains - so you need to set some preferred sizes, either the panel it
contains, ot the scrollpane itself (depending on how you set things up)