• Post Reply Bookmark Topic Watch Topic
  • New Topic

getLocationOnScreen() error with removed component  RSS feed

 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have the following:


it is from a simple clock bean I copied out of Matt Robinson's Swing book (page 143) . It can be added a bunch of times to a JFrame. I can add and delete the clocks, but when I delete one, I get an error at the line "Point pt1 = myActiveBean.getLocationOnScreen();" because that bean has already been deleted. The error says:

I also get the same error when resizing the JFrame that contains the clocks.
This is an error that happens when the downloadable code from that chapter is run. The bean seems to be removed but not set to null. I would like to fix it so it doesn't try to find the screen location of a bean that has already been removed from the container. I know that this is related to when repaint() is called and that is exactly why I am trying to figure this out.

here is the listener that actually deletes the bean.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK I solved the immediate problem with

myActiveBean.isShowing()

instead of

myActiveBean == null

but I would still like to know why ==null didn't work.

Tim
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!