String path = "path_to_image"; JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel(new ImageIcon(path)); label.setHorizontalAlignment(JLabel.CENTER); panel.add(label); // default center section
출처: http://www.java-forums.org/new-java/4477-how-add-images-jpanels.html
패널에 Layout을 설정하지 않을 시
class Pseudo extends JPanel {
BufferedImage image;
Pseudo(BufferedImage image) {
this.image = image;
// or load it in this class
setLayout(null);
add components...
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int x =
int y =
g.drawImage(image, x, y, this);
}
}
댓글 없음:
댓글 쓰기