ImageIconとテキストがあるJButtonがあります。 ボーダーのない透明な背景を持ちたいと思っていますが、パディングもしたいです。Jbuttonパディング付きの非表示の境界
Jbutton button = new JButton();
//Add image to the button
ImageIcon img= new ImageIcon(imgUrl);
button.setIcon(img);
//make button transparent
button.setBackground(new Color(255,255,255,0));
//Remove border
button.setBorderPainted(false);
button.setContentAreaFilled(false);
button.setFocusPainted(false);
//add padding
button.setBorder(BorderFactory.createEmptyBorder(5,10,5,50));
を私はまだ枠で灰色の境界線の周り参照してください。ここでは
は、私がしようとしているものです。 私はbutton.setBorder(null)を行うと灰色の境界線が消えるが、パディングを追加することはできない。
私が間違っていることについて誰かが私を導くことができれば。私は非常にスイングして、新しい答えを試したが、誰も働いていない。
ありがとうございます。
'button.setBackground(新色(255,255,255,0));'コンポーネントを透明にする方法ではなく、 'setOpaque'を設定してfalseを渡す必要があります – MadProgrammer
[' JButton#setMargin'](https://docs.oracle.com/javase) /8/docs/api/javax/swing/AbstractButton.html#setMargin-java.awt.Insets-)埋め込みを追加する場合 – MadProgrammer
@MadPro grammerはbutton.setMargin(新しいInsets(10,10,10,10))を試みましたが、nullとして設定された境界線では機能しませんでした。私が試すことができる他のものはありますか? – LearningToCode