Swing image class

B

bob smith

Is there really no built-in Swing class that just displays an image?

This is very hard to believe, but it looks like it at first google.
 
F

FredK

Is there really no built-in Swing class that just displays an image? This is very hard to believe, but it looks like it at first google.

What's wrong with using JLabel?
 
D

Daniel Pitts

Is there really no built-in Swing class that just displays an image?

This is very hard to believe, but it looks like it at first google.

JFrame mainFrame = new JFrame();
mainFrame.add(new JLabel(new ImageIcon(imageFile)));
mainFrame.pack();
mainFrame.setVisible(true);


Done.
 
A

Arne Vajhøj

Is there really no built-in Swing class that just displays an image?

This is very hard to believe, but it looks like it at first google.

Google was not your friend today.

:)

There are different ways of doing it.

JLabel lbl = new JLabel();
lbl.setIcon(new ImageIcon(location));
getContentPane().add(lbl);

is the simplest.

protected void paintComponent(Graphics g) {
super.paintComponent(g);
BufferedImage img = ImageIO.read(location);
g.drawImage(img, 0, 0, this);
}

gives you the option to play with AffineTransform.

Arne
 
R

Roedy Green

Is there really no built-in Swing class that just displays an image?

This is very hard to believe, but it looks like it at first google.

Perhaps they considered it too simple. Here is one

https://wush.net/svn/mindprod/com/mindprod/common11/ImageViewer.java

You can download the whole package at
http://mindprod.com/products1.html#COMMON11


You can use a JLabel/ImageIcon combo to get that effect in Swing.

see http://mindprod.com/jgloss/imageicon.html
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top