2012-10-31 49 views
2

我試圖創建一個簡單的按鈕,看起來應該像這個 -如何爲JButton設置「非常深藍色」的背景色?

enter image description here

JButton connectBtn = new JButton("Connect"); 
     Color blue = new Color(77,176,230);  
     connectBtn.setBackground(blue); 

但問題是背景藍色是不是變得像它看起來應該。

我已經嘗試了所有下面的可能性,但沒有用:-(

connectBtn.setBackground(Color.blue); 

connectBtn.setBackground(Color.BLUE.brighter()); 

connectBtn.setBackground(Color.decode("#0099cc"));//i tried simply #0099cc just to get any dark background 

的請幫我在這顏色設置爲背景的JButton感謝

+1

Printscreen - > Paint - > Colorpicker告訴我按鈕的顏色是'1691d9'(或'22,145,217'),如果有幫助的話。 – Keppil

+0

@Keppil AFAIU - 這實際上是'答案',儘管我不同意OP在圖像中是'非常深藍'。 –

回答

2

PRINTSCREEN - >顏料 - >色器告訴我,你的按鈕的顏色是

1691D9 

(22,145,217) 
+0

感謝您的回覆。實際上我已經嘗試了相同的RGB值。但看起來更輕。但是,如果將其設置爲「連接」按鈕上的文本,則顏色相同,但看起來較暗。不僅如此,任何顏色看起來都較暗的顏色不會;在JButton上看起來相同:-( – user1071096

2

Zoom顯示您的按鈕上塗有一個漸變,其中包含幾個藍色陰影以及反鋸齒文本。您可能需要一個合適的ButtonUI,如here所示,使用GradientPaint。請注意使用RenderingHints來建議別名設置。