当旋钮的图像上有鼠标时,如何将图像放在jslider的旋钮图像上 [英] how to put an image over jslider's knob image when mouse is present over the knob's image
本文介绍了当旋钮的图像上有鼠标时,如何将图像放在jslider的旋钮图像上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当鼠标出现在旋钮的图像上时,我需要将图像放在jslider的旋钮图像上。
I need to put an image over jslider's knob image when mouse is present over the knob's image.
我做过类似的事情。:
slider = new Slider();
s= new mySliderUI(slider ,"slider.png" );
slider.setUI(s);
slider.addMouseListener(new MyMouseAction());
public class MyMouseAction implements MouseListener{
public void mouseEntered(MouseEvent e) {
try {
s.knobImage = ImageIO.read(new File("slider_roll.png"));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public void mouseExited(MouseEvent e) {
try {
s.knobImage = ImageIO.read( new File("slider.png"));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
private class mySliderUI extends BasicSliderUI {
Image knobImage;
public mySliderUI( JSlider aSlider, String fileName ) {
super( aSlider );
aSlider.setPaintTrack(false);
aSlider.setBorder(null);
try {
this.knobImage = ImageIO.read( new File(fileName) );
} catch ( IOException e ) {
e.printStackTrace();
}
}
public void paintThumb(Graphics g) {
g.drawImage( this.knobImage, thumbRect.x, thumbRect.y, 10, 15, null );
}
}
上述代码不管用。请告诉我该怎么做。
The above code is not working. Please tell me how can i do this.
谢谢
Jyoti
Thanks Jyoti
推荐答案
鉴于您似乎没有接受答案,并且您尚未发布 SSCCE 再一次,我不会花太多时间猜测你在做什么。
Given that you don't seem to accept answers, and given that you haven't posted a SSCCE yet again, I'm not about to spend much time guessing what you are doing.
我唯一的建议就是你需要使用滑块。更改图像后重绘()
。此外,您不应该每次都阅读图像。图像应该被缓存。
The only suggestion I have is you need to use slider.repaint()
after changing the image. Also you should not be reading the image every time. The image should be cached.
这篇关于当旋钮的图像上有鼠标时,如何将图像放在jslider的旋钮图像上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文