i have added a picture panel in jscroll pane

scrollpane.add(pic1);

now i want that on run time when user click on another pic panel it will be shown at pic1 scroll pane, so i simply use this code

scrollpane.add(pic2);

but it doesnt work , so i searched a bit over internet and find some threads about repaint , revalidate and validate function , i use them all but nothing work...

scrollpane.add(pic1);
scrollpane.removeall();
scrollpane.revalidate();
scrollpane.repaint();
scrollpane.add(pic2)
scrollpane.revalidate();
scrollpane.repaint();

Thats what i got .... i have explained every thing, kindly please help..................

create new logics JScroolPane - > JPanel - > JLabel -> ImageIcon, then just swith Image in JLabel then call revalidate(); and repaint(), nothing else JLabel is in this case better as JPanel

why java not support direct assignement.... i m doing every thing according to logic... Thanx for above suggestion. I already did that... but i dont want that method i want direct assignement... its my home work...

You need to set the view on the viewport

scrollpane.getViewport().setView(pic2)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.