[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

Problem in getting "bounds" property in Introspection

Hi all,

I am facing a problem for "bounds" property (i.e. getBounds() and setBounds for Component class). Problem is I am not getting "bounds" property listed in propertydescriptor of a component. And I have to use propertydescriptor to use name of the property to get notified that a particular property is changed. I get notification for all properties except "bounds" property (using PropertyChangeListener). So, Please provide help for solving this problem. I don't get any information regarding this issue on any site. One more thing. Here "bounds" property means "setBounds" and "getBounds" of a component and not Bound and Constraint properties of JavaBeans. Please give any suggestion.

regards,

Sanket.
0
SanketDesai
Asked:
SanketDesai
  • 5
  • 4
  • 3
2 Solutions
 
objectsCommented:
Use a ComponentListener to listen for size changes.
0
 
RodionPCommented:
As far as I understood your question, getBounds returns a Rectangle of the bounds of current component that is drawn on the screen in pixels. please let me know what exactly does it return, I sense some misinterpritation of the data, beacause I always used that fucntion and I never had any problems.
I also think that PropertyChangeListener is not the one you should be using for component size change. ComponentListener should be used, componentResized() in particular
0
 
SanketDesaiAuthor Commented:
Hi RodionP,
         Thanks for your suggestion. Actually my problem is i want to be notified by propertychangelistener whenever size of a component is changed (i.e. using setbounds or setsize etc..). Simple reason for this is that i want old and new values both for this property. Suggestion for componentlistener can not be used because it just gives me new set of values and not old values. I hope you are getting my problem. As far as I know it is almost impossible to get old and new values both for "bounds". Please give me any suggestions you have. Suggestions and questions are always welcome!.

Thanks,

Sanket.


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RodionPCommented:
Well, how about you just keep 2 values (variables of type Rectangle would be best I think), one old and one new, on every resize event performe the following:

public void componentResized(ComponentEvent e){
    oldVvalue = newValue
    newValue = this.getSize();
}

simple as that, and at any given moment you will always have 2 copies of the size, which are current size and old size.

That is how animation works, they keep 2 copies of some shape that has to be drawn, and they set the XOR mode for drawing, and in each frame they draw the old value (that overlaps with previously drawn shape and consequently erases it) and draw the new one.
0
 
objectsCommented:
> Simple reason for this is that i want old and new values both for this property

if you want the old value then just remember it as suggested by RodionP.
You could even create a ComponentListener that fired a PropertyChangeEvent if you wanted.
0
 
SanketDesaiAuthor Commented:
Hi RodionP and objects,

         Thank you very much taking keen interest in this problem. I really appreciate your suggestions. But still i am unable to get my solution. Let me explain the whole scenario in detail. I am developing Undo/Redo framework for a product (but I am trying to make it generalized). This product is already in working condition. So, this framework is enhancement. I can't change any already written code. Considering these points, The only way i can be notified about propertychange is propertychangelistener. I can't keep track of both old and new set values for each and every component, because how many components will be added at run time that can't be predicted. Lets hope for solutions. Once again thanks for taking such interest.

Sanket.
0
 
objectsCommented:
Why won't my suggestion above work, ie. use a ComponentChangeListener that fires PropertyChangeEvents.
0
 
SanketDesaiAuthor Commented:
Hi objects,

           If i incorporate your suggestion in my application, then it would become the soultion of this product only. As in my previous comment i have clearly mentioned that i want to make this framework generalized one. So, once a component is added, all properties of that component should be undone and redone and that is also using propertychangelistener. Let us say NO OTHER OPTION is available for me other than to use propertychangelistener. If you have any suggestions (using propertychagelistener) then please let me know!. Thanks for your comment.

Sanket.
0
 
objectsCommented:
then you cannot do it because Component do not fire PropertyChangeEvent's when they change size.
0
 
RodionPCommented:
Well, my suggestion would be the following, how all general undo/redo work, every program has a model behind it, some data structure that describes the problem, engine so to speak... (In MS Word this is a document in Windows this is some state of machine at a given moment). So when any changes occur, the model behind changes, and representation of that model will consequently change. So if you want it generalized, keep instances of your engine, or some portions of it depending on the implementation. It is important to understand that GUI is simply a matter of representation and there are many representations of some abstract object, undo/redo functionality should be dependant on the representation. I am probobly getting too general and theoretical, but that is the way I see it, and that is the way how I implement undo/redo in all the applications I have written.

However I cannot help you with propertychangelistener, you have to implement your own listeners and events that in some way incorporate ComponentEvent
0
 
SanketDesaiAuthor Commented:
Hi both of you,

        Though i have not got exact answer for my problem, i have got some hint for that indeed. Thanks for your reponses!

Sanket.
0
 
objectsCommented:
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now