Solved

How do I display a bmp on an AWT panel?

Posted on 2001-06-04
5
220 Views
Last Modified: 2013-11-19
How do I display a jpg on an AWT panel?
0
Comment
Question by:hmsjavateam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 27

Expert Comment

by:rrz
ID: 6152733
Use A program such as MS Paint to convert to .gif or .jpg
then Java can accept it.
0
 

Expert Comment

by:JDay
ID: 6153983

You need to tell your program where to find the file.
I think that there are other image objects that you can use besides the icon object. It depends on what you are using.

Icon TrashIcon = new ImageIcon("c:\\TrashIcon.gif");

Then you add the Icon to the panel and set the size and location.

JDay
0
 

Expert Comment

by:SimonSay
ID: 6154963
Which one do you want to display, bmp or jpg?
Java can only display JPG and GIF files. As rrz said, you have to convert your bmp to jpg/gif first.

To display an jpg/gif image, you can do something like this in your public void paint method (assume you are in an applet)

...
Image myimg = getImage(getCodeBase(), "images/mypic.jpg");
...
...
public void paint(Graphics g)
{
   g.drawimage(myimg, x, y, this);
}
//where x, y are the coordinates on the applet

0
 

Author Comment

by:hmsjavateam
ID: 6156961
I need to know how do I display a jpg on an AWT panel running under an application (not an applet), or how to extend applet instead of panel, but load the pannel in an application.
0
 

Accepted Solution

by:
rubenbouman earned 50 total points
ID: 6162706
the comment given by "Simon Say" is for an applet. This code is for an application:

Toolkit tk = Toolkit.getDefaultToolkit();
Image myimg = tk.getImage("c:/images/mypic.jpg");
...
...
public void paint(Graphics g)
{
  g.drawimage(myimg, x, y, this);
}
//where x, y are the coordinates on the panel
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 129
Why my table column Id is not passed to java object? 4 46
throw exception 21 69
collection output issue 9 66
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
It’s easy to embed any of your public Prezi presentations on your website or social network to share with others. Learn how simple it is in this tutorial.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question