2015-11-05 32 views
0

我想更改我的JLabel的背景,其格式爲JScrollPaneRowHeaderViewJScrollPane背景中的JLabel不更改

JLabel jl = new JLabel("asdfasdfasdf"); 
jl.setForeground(Color.RED); 
JScrollPane scroll = new JScrollPane(); 

// I Have tried 
jl.setBackground(new Color(0, 0, 0, 255)); 
scroll.setBackground(new Color(0, 0, 0, 255)); 
scroll.setOpaque(true); 
scroll.setVisible(true); 

scroll.setRowHeaderView(jl); 

但是文字是紅色的,但背景仍然是白色。

編輯

這是How do I set a JLabel's background color?重複,但我無法設置這個問題作爲一個重複自己,因爲我需要250代表。

+2

'jl.setOpaque(true);'? –

+0

哦......不......我錯過了......請在下面回答。 –

+5

http://stackoverflow.com/questions/2380314/how-do-i-set-a-jlabels-background-color – Husam

回答

2

JLabel的默認不透明度爲false。這意味着不可見。 使用jl.setOpaque(true);

祝你好運。