Solved

How do I display a bmp on an AWT panel?

Posted on 2001-06-04
5
211 Views
Last Modified: 2013-11-19
How do I display a jpg on an AWT panel?
0
Comment
Question by:hmsjavateam
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
parentbit challenge 3 52
strDist challenge 35 84
Unable to start eclipse ? 17 86
Java / Linux and Regular Expressions 11 47
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Add visuals to your Prezi to keep your audience engaged. Learn how to embed images, edit them, and more in this video micro tutorial. Select "Insert" from the top menu in your Prezi editor: Select "Image": A toolbar will pop in from the right …
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now