Rob Camick wrote:Check out How to Write a Component Listener. You can handle the componentMoved() event.
Rob, thanks for your answer. But I don't want to handle the componentMoved event. The whole reason behind using the data binding model, that the component that fired the propertyChanged event doesn't know anything about interested parties, which makes sense in this use case. So I insist on handling the propertyChanged event, just not quite sure how to implement that.
Anton Shaykin wrote:I guess it has something to do with the fact, that the components are inside different panels.
I don't see why that would have anything to do with it. And also you could test that hypothesis by putting the components into the same panel.
2) you also need to add the listener to the component whose property has changed:
Once you do this you will get your event but you will notice a problem that the label doesn't move. This is because when you change the text on the label the panels are revalidated and the location of the moving label is reset to the location determined by the layout manager. A fix for this is to use:
So basically we are back to my original suggestion to just use a ComponentListener so you don't have to generate your own property change event. The ComponentListener needs to be added to the component that moves and the listener updates the label with the text.
Rob Camick wrote:So basically we are back to my original suggestion to just use a ComponentListener so you don't have to generate your own property change event.
I tried your suggestion with the same results - label ceases to move
Darryl Burke wrote:Did you think the "location" property of destLbl would change when you move testLbl?
No, I think that the destLbl is the one who needs to handle the location changes of testLbl.
Darryl Burke wrote:No response for nearly 5 hours
Sorry, that's because of the time zone difference.
So the only way to make it work with PropertyChangeListener is to set null layout?
This has nothing to do with the propery change listener. This is how layout managers work.
When you update the text of the label, the label is revalidated. This can cause the all the panels to be revalidated and therefore the layout manager overrides the location you set on the component with a location determined by the rules of the layout manager.
This will happen if you use a ComponentListener or any other listener.
If you want to randomly set the location of components on a panels because you are dragging the component or whatever, then yes you need to set the location (and the size) of the component manually and you need to use a null layout manager.
Rob Camick wrote:If you want to randomly set the location of components on a panels because you are dragging the component or whatever, then yes you need to set the location (and the size) of the component manually and you need to use a null layout manager.
Thanks a lot! That really gave me great understanding of what's going on here!
1) Why changing text of one label causes revalidation of all the panels, while moving a single component doesn't revalidate anything? If that's a normal behavior, is there any way to prevent the validation of the whole contentPane?
2) Concerning property change listener... Is there any way to fire the event, sort of, globally, so that other components can receive it? I just don't get the concept - why the component that triggered the event (moving label) should handle that event (that is to add property change listener)? The moving label might not even be aware of a label that needs to be updated.