Solved

Problem in getting "bounds" property in Introspection

Posted on 2003-12-10
12
277 Views
Last Modified: 2012-05-04
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
Comment
Question by:SanketDesai
  • 5
  • 4
  • 3
12 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9918580
Use a ComponentListener to listen for size changes.
0
 
LVL 1

Expert Comment

by:RodionP
ID: 9922541
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
 
LVL 1

Author Comment

by:SanketDesai
ID: 9940937
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 1

Expert Comment

by:RodionP
ID: 9942683
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
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 9944464
> 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
 
LVL 1

Author Comment

by:SanketDesai
ID: 9947476
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
 
LVL 92

Expert Comment

by:objects
ID: 9947495
Why won't my suggestion above work, ie. use a ComponentChangeListener that fires PropertyChangeEvents.
0
 
LVL 1

Author Comment

by:SanketDesai
ID: 9947525
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
 
LVL 92

Expert Comment

by:objects
ID: 9947603
then you cannot do it because Component do not fire PropertyChangeEvent's when they change size.
0
 
LVL 1

Accepted Solution

by:
RodionP earned 150 total points
ID: 9954243
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
 
LVL 1

Author Comment

by:SanketDesai
ID: 10171319
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
 
LVL 92

Expert Comment

by:objects
ID: 10171344
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Spring Framework HTTPSession management 1 36
javap bin 2 36
fibonacci ten numbers 4 39
runtime exception 2 29
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question