This is your first problem (and possibly your second)
public void paintComponent(Graphics g)
{
g.setColor(color);
setBorder(BorderFactory.createLineBorder(border, 2));
}
Firstly, you must call super.paintComponent
or take responsibility for its actions. This will clear and prepare the Graphics
context for further painting.
Secondly, you should never modify any UI component from within a paintXxx
method that may cause it be invalidated or repainted. Doing so will end you an infinite loop of burning CPU...
Set the border within the constructor or change it as the program needs, do not do so from within the paint
method...
Updated with additional examples
When you need to change the border, simply call setBorder
on the instance of the title you want change....
public Tile(Color _color, Color _border)
{
color = _color;
border = _border;
setBorder(BorderFactory.createLineBorder(border, 2));
}
or
Title tile = new Tile(Color.RED, Color.BLUE);
//...
title.setBorder(BorderFactory.createLineBorder(Color.GREEN, 2));
Check out How to use borders for more info...