• Post Reply Bookmark Topic Watch Topic
  • New Topic

Image Display in a Jframe  RSS feed

 
matt prowell
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having problems figurig out how to display a image in a Jframe. I found some where that


Image figure = Toolkit.getDefaultToolkit( ).getImage(filename);
getContentPane().add(new JScrollPane(new ImageComponent(figure)));


would work. But it doen't. Any suggestions? Thanks.

Matt
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

The easiest way to add a picture to your frame is to put the picture onto a label like this...

public ImageIcon SENDicon = new ImageIcon("./images/toolbar/send.gif");

Then you make your JLabel and use the methods that you find in the API to set the Image. (PS, the image in this case is an icon)

Look in the API's and then ask if you need more help.

Rachel
 
matt prowell
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to mention onething not sure if this will have an effect on how it should be done. I need to have and image on the left and a text field on the right. Thanks.
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, well then you have a JPanel with a LayoutManager. To this you add the label and the textfield to whatever side you need.
 
matt prowell
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanks i will try that
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing forum.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!