Problem in using JScrollPane
hiii i am creating an image editor in java...
here is my code for using scrollpane
contentpane = getContentPane();
view =new JLabel(new ImageIcon(bufferedImage));
scrollpane =new JScrollPane(view,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollpane.setPreferredSize(new Dimension(800,600));
contentpane.add(scrollpane);
The problem is that the content of viewport does not change...i.e if i apply any effect to an image....after that as soon as i use the scrollbar, the viewport displays the original image!!!
What is the problem?
could someone suggest a solution?
[814 byte] By [
rav_ahja] at [2007-11-26 21:53:40]

# 2
Going on what you've said, I suspect you have a fundamental misunderstanding of how references operate.
You will have to call setIcon() on your label after modifying the image. If you change "bufferedImage" then you are just changing that reference. The image used by the icon in the label is not changed.
eg.String a = "a";
String b = a;
b = "b";
System.out.println(a);
will result in the output "a" - not "b"
Of course I may have misunderstood you...
# 6
Can you plzz help me with this?...it is very urgent...
As i am creating an image editor, so the scrollpane must be updated as soon as i apply any effect to it .....
along with that whenever a user selects a file from FileDialog...then also it must be updated!!!
I have extended JFrame for my main class.
//this is the code i have written when user selects a new file...
contentpane = getContentPane();
view = new JLabel(new ImageIcon(bufferedImage));
view.setVisible(true);
crollpane = newJScrollPane(view,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollpane.setPreferredSize(new Dimension(200,200));
contentpane.add(scrollpane);
// This is the code for scollpane update
iicon.setImage(bufferedImage);
view.setIcon(iicon);
scrollpane = new JScrollPane(view,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollpane.setPreferredSize(new Dimension(200,200));
contentpane.add(scrollpane);
scrollpane.updateUI();
Message was edited by:
rav_ahj