现在我在这里创建按钮如何在按钮上设置图像 [英] now am create button here how set image on the button
本文介绍了现在我在这里创建按钮如何在按钮上设置图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private JPanel addToolbar() {
JPanel jp1=new JPanel();
jp1.setLayout(new FlowLayout());
JButton jb7=new JButton("exit ");
jb7.addActionListener(this);
jb7.setForeground(new Color(00,00,255));
jp1.add(jb7);
这里如何将图像设置在按钮字段附近这是按钮创建代码但是如何在图像上设置图像按钮字段
here how to set the image near to the button field this is button create code but how can i set image on the button field
推荐答案
通过阅读您的问题,我认为您想在按钮上添加图像。您可以尝试这样的事情:
By reading your question I think that you want to add an image on your button. You could try something like this:
import javax.imageio.ImageIO; //needed
import java.io.File;
public void initialize(){
//create your jframe
//add you panel to it
//add your button, set the actionListeners etc.
File imageFile=new File("yourImage.png");
Image image=ImageIO.read(imageFile);
yourButton.setIcon(new ImageIcon(image));
}
这应该可以解决问题。
最好的问候。
This should do the trick.
Best regards.
您好,
在表格和按钮的onclick事件中有一个图像标签和一个按钮,写下如下内容:
Hi,
Have an image tag and a button in your form and on the onclick event of the button, write something as below:
protected void button_click()
{
ImageID.ImageUrl="Images/pic.jpg";
}
应该这样做。
It should do the trick.
JButton button = new JButton();
try {
Image iconImg = ImageIO.read(getClass().getResource("resources/test.bmp"));
button.setIcon(new ImageIcon(iconImg));
} catch (IOException ex) {
}
这里,假设图像文件位于src / resources文件夹中。
Here, image file is assumed to be inside src/resources folder.
这篇关于现在我在这里创建按钮如何在按钮上设置图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文