Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert an image in JScrollPane

 
Udaya Wijenayake
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it. Now its working. Thanks for the help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic