Solved

Problem in getting "bounds" property in Introspection

Posted on 2003-12-10
12
274 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
triangle challenge 4 77
stringclean challenge 26 56
What is JNDI datasource in spring 1 38
Requested array size exceeds VM limit 3 48
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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now