怎样实现点击jLabel,将里面的图片显示在另一个jScrollPane里?

05-12-14 rosefish
我在jLabel里装载了一些图片

imgs=new ImageIcon(this.getClass().getResource("img/"+s+".jpg")).getImage();

BufferedImage bf=new BufferedImage(130,92,BufferedImage.TYPE_INT_ARGB);

bf.getGraphics().drawImage(imgs,0,0,130,95,null);

JLabel label=new JLabel(new ImageIcon(bf));

jPanel.add(label);

想点击其中一张图片,使其相应鼠标事件,在另一个jScrollPane里显示出来!

请大家指教!

banq
2005-12-15 11:29
加入listern即可

rosefish
2005-12-15 14:03
谢谢,我加入了鼠标侦听:

label.addMouseListener(new java.awt.event.MouseListener() {

public void mouseClicked(java.awt.event.MouseEvent e) {

jLabel3.setIcon(((JLabel)e.getComponent()).getIcon());

}

public void mousePressed(java.awt.event.MouseEvent e) {

//System.out.println("mousePressed()");

}

public void mouseReleased(java.awt.event.MouseEvent e) {

//System.out.println("mouseReleased()");

}

public void mouseEntered(java.awt.event.MouseEvent e) {

//System.out.println("mouseEntered()");

}

public void mouseExited(java.awt.event.MouseEvent e) {

//System.out.println("mouseExite()");

}

});

但是jLabel3里显示出来的图片跟侦听的jLabel中的图片一样大,我想放大显示在jLabel3中,请问怎样实现呢?

谢谢!

rosefish
2005-12-16 11:45
问题已解决!

Thanks!

猜你喜欢