Date of registration: Oct 17th 2003
Location: Dresden
Occupation: Um ein bißchen mehr Ahnung zu haben als andere
Quoted
public class ImageComponent extends Component {
private static final long serialVersionUID = 1L;
private Image img;
public ImageComponent(Image img) {
this.img = img;
}
@Override
public void paint(Graphics g) {
if (img!=null) {
g.drawImage(img, 0, 0, this);
}
}
@Override
public Dimension getPreferredSize() {
if (img==null) return new Dimension(0,0);
return new Dimension(this.img.getWidth(this),this.img.getWidth(this));
}
}
Quoted
Image pic = Toolkit.getDefaultToolkit().getImage( "bild.jpg" );
ImageComponent img = new ImageComponent(pic);
JScrollPane sp = new JScrollPane(img);
sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
This post has been edited 1 times, last edit by "Hogi" (Apr 26th 2006, 4:54pm)
Date of registration: Oct 17th 2003
Location: Dresden
Occupation: Um ein bißchen mehr Ahnung zu haben als andere
![]() |
Source code |
1 2 3 |
ImageIcon icon = new ImageIcon(KLASSENNAME.class.getResource("picture.jpg")); JLabel l1 = new JLabel(icon); jPanel.add(l1); |
This post has been edited 1 times, last edit by "Lucky" (Apr 26th 2006, 7:19pm)