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]
# 1
In this the variable bufferedImage gets updated as sson as any effect is applied to the image!!
rav_ahja at 2007-7-10 3:48:05 > top of Java-index,Desktop,Core GUI APIs...
# 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...

itchyscratchya at 2007-7-10 3:48:05 > top of Java-index,Desktop,Core GUI APIs...
# 3
i Tried using that i first did................iicon.setImage(bufferedImage);view.setIcon(iicon); but it gives null pointer exception after the iicon.setImage(bufferedImage) statment!!
rav_ahja at 2007-7-10 3:48:05 > top of Java-index,Desktop,Core GUI APIs...
# 4
Then I expect "bufferedImage" is null.
itchyscratchya at 2007-7-10 3:48:05 > top of Java-index,Desktop,Core GUI APIs...
# 5
no its not...i have checked it using a breakpoint!!!right after iicon.setImage(bufferedImage);it gives a null pointer exception!!!!!
rav_ahja at 2007-7-10 3:48:05 > top of Java-index,Desktop,Core GUI APIs...
# 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

rav_ahja at 2007-7-10 3:48:05 > top of Java-index,Desktop,Core GUI APIs...
# 7
Don't you think it might be useful to show us the stack trace from the exception?
itchyscratchya at 2007-7-10 3:48:05 > top of Java-index,Desktop,Core GUI APIs...