English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

in java, is it possible to put an image to gui, w/o using an applet?, like to put it in a JLabel, or as a background for a JPanel

2007-08-07 03:48:07 · 2 answers · asked by joseng_12 2 in Computers & Internet Programming & Design

2 answers

We do this:

===================
Image image = Toolkit.getDefaultToolkit( ).getImage( imageFileName);
ImagePanel imagePanel = new ImagePanel( image);
logoPanel.add( imagePanel, BorderLayout.EAST);
====================

But we implemented ImagePanel on our own. It's pretty simple, though:

====================
public class ImagePanel extends JPanel {
private static final long serialVersionUID = 1L;
private Image image;
public ImagePanel(LayoutManager layout, boolean isDoubleBuffered) {
super(layout, isDoubleBuffered);
}

public ImagePanel(Image image) {
this.image = image;
}

public void paintComponent(Graphics g) {
super.paintComponent(g); //paint background
g.drawImage(image, 0, 0, this);
} }
====================

2007-08-07 03:53:29 · answer #1 · answered by McFate 7 · 0 0

Computer Tutorials, Interview Question And Answer
http://freshbloger.com/

Java tutorials- http://java-tip.org/

java architecture tutorial
http://java3.blogspot.com/

2007-08-07 08:39:27 · answer #2 · answered by aerokan a 3 · 0 1

fedest.com, questions and answers