Java中jbutton 设置背景图片之后还能加文字吗
packagecom.lxit.gui.mycomponent;importjava.awt.Graphics;importjava.awt.Graphics2D;imp...
package com.lxit.gui.mycomponent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JButton;
public class MyButton extends JButton {
Image image = Toolkit.getDefaultToolkit().getImage("x.jpg");
public MyButton(String name) {
super(name);
}
public void paintComponent(Graphics gs) {
// 画背景图片
gs.drawImage(image, 0, 0, 40, 20, this);
Graphics2D g = (Graphics2D) gs;
super.paintComponent(g);
}
} 展开
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JButton;
public class MyButton extends JButton {
Image image = Toolkit.getDefaultToolkit().getImage("x.jpg");
public MyButton(String name) {
super(name);
}
public void paintComponent(Graphics gs) {
// 画背景图片
gs.drawImage(image, 0, 0, 40, 20, this);
Graphics2D g = (Graphics2D) gs;
super.paintComponent(g);
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询