my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Insert an image in JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Insert an image in JScrollPane" Watch "Insert an image in JScrollPane" New topic
Author

Insert an image in JScrollPane

Udaya Wijenayake
Ranch Hand

Joined: May 15, 2009
Posts: 30
Hi everyone,

In my application when I click the jButton1 it load a file using JFileChooser and then i want to dispaly it in jScrollPane1.
I used the following code inside jButton1ActionPerformed area.



but it doesn't display the image. So can you help me to display the image in jScrollPane1 area.
Here is the full code of my application.



SCJP 1.5
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
no need to create another scrollpane,
just add the label to the existing scrollpane,
via the viewport

ImageIcon ii = new ImageIcon(file_path);
jScrollPane1.setViewportView(new JLabel(ii));
Udaya Wijenayake
Ranch Hand

Joined: May 15, 2009
Posts: 30
I got it. Now its working. Thanks for the help.
 
jQuery in Action, 2nd edition
 
subject: Insert an image in JScrollPane
 
Similar Threads
How can i display minimize and iconifiable button in JInternalFrame
Pressing a button to open a new window
Line Spacing in jTextPane
adding and manipulating elements of a CCombo
Refreshing a window