2

I am working on a big application with lots of components in it. I am trying to add a comboBox at one place and Container is removing that component before it is visible. I read some where that Java Swing validates and removes the component if it is aded somewhere else. How does that exactly works ?

I am sorry but I guess this problem is too abrupt and I am not able to provide any code.

P.S. checked every property of component,panel and container and there is nothing which is affecting the visibility of component.

arpanoid
  • 2,123
  • 4
  • 17
  • 15

2 Answers2

3

I never see that Container is removing that component before it is visible, how and what did you debug that, are you sure that JComboBox was added to the expected and visible Container, btw there are lots of threads about How to Add/Remove JComponent(s) on Runtime here is guide from last/recent posts about that,

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • yes I am sure that JComboBox was added to correct visible Container. Although there are several threads working on it.Your link was very helpful. – arpanoid Aug 19 '11 at 19:33
  • are you debug where, how and what's getBounds returns and if in visible Rectangle..... – mKorbel Aug 19 '11 at 20:29
  • 2
    @arpanoid: you shouldn't have multiple threads accessing your combo box. Only the EVent Dispatch Thread should access it. See http://download.oracle.com/javase/6/docs/api/javax/swing/package-summary.html#threading – JB Nizet Aug 19 '11 at 20:58
3

What you've read is that you can add a component to only one visualized container. If you add the component to multiple containers it will only be visualized in one of them. Other than that, Swing will not randomly remove components from containers, so if the first thing that I mentioned is not your issue, you've got a bug in your program, and we'll need to see code to figure out what it is. Best would be if you could create and post an SSCCE

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373