• Post Reply Bookmark Topic Watch Topic
  • New Topic

Newbie question.  RSS feed

 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I am doing this wrong.. but I have a square I display
in the paintComponent(Graphics g) method of a panel.

And all I want to do is
show the square in a blue background whenever the mouse hovers anywhere inside the square and from what I understand, I have to call repaint() on the entire panel to have that done??
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I have to call repaint() on the entire panel to have that done??

from your description, it is the graphics object of the panel that draws the
square in the first place, so it would have to repaint the entire panel.

an alternative could be to make your 'square' a separate panel (with border)
add this panel to the other panel
the mouseListener enter/exit code can then just call repaint of the 'square' panel
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!