I am trying to decorate a JLabel
but the proprieties i set don't work .
Decorator Class :
public class Decorator extends JComponent{
public Decorator(JComponent c){
setLayout(new BorderLayout());
add("Center",c);}
}
PlayLabel class :
public class PlayLabel extends Decorator{
JComponent thisComp;
public PlayLabel(JComponent c){
super(c);
thisComp=this;
LineBorder line = new LineBorder(new Color(36,77,240), 2, true);
thisComp.setAlignmentX(Component.CENTER_ALIGNMENT);
thisComp.setBackground(new Color(36,77,240));
thisComp.setMaximumSize(new Dimension(150,75));
thisComp.setForeground(Color.WHITE);
thisComp.setOpaque(true);
thisComp.setFont(new Font("Times New Roman",Font.BOLD,35));
//thisComp.setHorizontalAlignment(SwingConstants.CENTER);
thisComp.setBorder(line);
c.addMouseListener(new MouseListener() {
@Override
public void mouseEntered(java.awt.event.MouseEvent evt) {
thisComp.setBackground(new Color(96,125,244));
}
@Override
public void mouseExited(java.awt.event.MouseEvent evt) {
thisComp.setBackground(new Color(36,77,240));
}
});
}
}
I have a JPanel
in a jFrame
where i add PlayLabel
like this :
panel.add(new PlayLabel(new JLabel("PLAY")));
These proprieties don't work as intended for the PlayLabel i created :
thisComp.setAlignmentX(Component.CENTER_ALIGNMENT);
thisComp.setBackground(new Color(36,77,240));
thisComp.setMaximumSize(new Dimension(150,75));
thisComp.setForeground(Color.WHITE);
thisComp.setFont(new Font("Times New Roman",Font.BOLD,35));
What am I doing wrong ?