JButtonに背景色のみを表示させる最も簡単な方法は何ですか?ボーダー、3Dルック、ホバーハイライトなどの他のエフェクトは必要ありません。
前もって感謝します。
ポイントを逃したかどうかはわかりません...しかし、私は通常、次のようなことをします:
button.setBorderPainted(false);
button.setFocusPainted(false);
button.setContentAreaFilled(false);
色と境界線を設定するだけです:
private static JButton createSimpleButton(String text) {
JButton button = new JButton(text);
button.setForeground(Color.BLACK);
button.setBackground(Color.WHITE);
Border line = new LineBorder(Color.BLACK);
Border margin = new EmptyBorder(5, 15, 5, 15);
Border compound = new CompoundBorder(line, margin);
button.setBorder(compound);
return button;
}
setOpaque(false);
背景を透明にするために使用します。
どうですか
yourButton.setBorder(null);
?
まず、ルック アンド フィールを「メタル」などのクールなものに設定します。
try
{
for (UIManager.LookAndFeelInfo lnf :
UIManager.getInstalledLookAndFeels()) {
if ("Metal".equals(lnf.getName())) {
UIManager.setLookAndFeel(lnf.getClassName());
break;
}
}
} catch (Exception e) { /* Lazy handling this >.> */ }
次に、次のようにします。
my_jbutton.setBackground(new Color(240,240,241);
ボタンの色がスイング コントロールの色 (240、240、240) と正確に等しい場合、ウィンドウはウィンドウのようなボタン スタイルをボタンに適用します。それ以外の場合、ボタンは単純なフラット スタイルを想定します。
代わりに JLabel を MouseListener で使用することをお勧めします...何らかの方法で JButton または ActionListener を使用することに縛られている場合を除きます。
私はあなたがこのようにすることができると思います
JButton button = new JButton("Click Me!!");
button.setBorderPainted(false);
button.setBackground(new Color());// inside the brackets your rgb color value like 255,255,255
button.setFocusPainted(false);
カラーピッカーを使用してRGBコードを取得できます(カラーピッカーを検索するだけです)