JButtonにカスタム画像を使用しようとしましたが、周囲に白いボックスがあることを除けば、うまく機能します。これを修正する方法がわかりません。助けが必要です。(新しいImageButton( "Quit"、 "src / button.png"、128、64)を使用してボタンを作成します。ボタンのサイズは変更できず、画像ファイルは256X128です)
ボタンクラス:
public class ImageButton extends JButton {
Image image;
ImageObserver imageObserver;
public ImageButton(String text, String filename, int width, int height) {
super(text, new ImageIcon(filename));
setSize(width, height);
setHorizontalTextPosition(JButton.CENTER);
setVerticalTextPosition(JButton.CENTER);
}
}
getInsetsオーバーライドを使用した画像: