I need to create a class XLabel
that would have customized color and font.
I need all JLabels
to have the following effect
JLabelTest.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
JLabelTest.setForeground(Color.PINK);
This is what I tried
public class XLabel extends JLabel {
@Override
public void setFont(Font f)
{
super.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
repaint();
}
@Override
public void setForeground(Color fg)
{
super.setForeground(Color.PINK);
repaint();
}
}
However, when I try to use it XLabel test= new XLabel("test")
does not compile , because constructor XLabel (String )
is undefined. But it extends JLabel
, so it should inherit all it's constructors . Why doesn't it ? How to set customized color and font ?