hanvyj 7 Posting Whiz in Training

I have a bit of a puzzle, My default buttons (for when they are only an image) have this "highlight" listener, when the mouse enters/exits it draws a border to give the user some feedback.

Its worked fine untill now, where I have a "close" button that, when clicked, removes the panel its on from the container.

When this panel is added, the button remains permanently highlighted. This is because the button is removed, while the mouse is within it - so it never "leaves" the button, and when the panel is shown again it is still classed as being highlighted.

I could fix this by calling a method to un-highlight the button when it hides iteself but I was wondering if anybody could think of a more elegant solution...

class ButtonBorderHighlightListener extends MouseAdapter
{
	private Border origional;
	
	public void mouseEntered(MouseEvent e)
	{
		JayButton source = (JayButton)e.getSource();
		origional = source.getBorder();
		//source.setBorder(BorderFactory.createMatteBorder(1,1,1,1, Color.DARK_GRAY) );// .createLineBorder(Color.DARK_GRAY,1));
		source.setBorder(BorderFactory.createLineBorder( new Color(250, 188, 94),2));
	}
	
	public void mouseExited(MouseEvent e)
	{
		JayButton source = (JayButton)e.getSource();
		source.setBorder(origional);
	}
}

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.