JLabel设置颜色

用到JLabel设置颜色。setBackground(Color color)。结果没显示。网上看了看都说加上html就行了。觉得不好。再搜。原来还有个setOpaque(boolean bool);这个方法设置true就可以了。原来这是设置透明度,java默认是设置的false。即透明。(opaque,经过翻译是不透明的意思。呵呵)。只要设置成不透明,颜色自然看到了。
把该方法贴一下

public void setOpaque(boolean isOpaque)
If true the component paints every pixel within its bounds. Otherwise, the component may not paint some or all of its pixels, allowing the underlying pixels to show through. 
The default value of this property is false for JComponent. However, the default value for this property on most standard JComponent subclasses (such as JButton and JTree) is look-and-feel dependent. 


Parameters:
isOpaque - true if this component should be opaque
See Also:
isOpaque()



你可能感兴趣的:(java,html)