File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Selection rectangle on image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Selection rectangle on image" Watch "Selection rectangle on image" New topic
Author

Selection rectangle on image

Prathyusha Tummepalli
Greenhorn

Joined: Sep 17, 2012
Posts: 3
Hiii... I have a similar problem like this...

I created a frame which will have a label to show an image and i am able to display the image. User needs to select some part of the image as rectangle,Here i am able to draw rectangle but it is disappearing when i stop the mouse dragging only.. Here is my code.. Could you please help me what is my mistake and what i need to add?
As I am new to graphics, can you please give me the code clearly which is need to be added or modified...

Thanks In advance

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4529
    
    5

If it was a similar problem, either or both of the solutions offered in the thread this was removed from should have sufficed.

When posting code, please UseCodeTags <- link

Here i am able to draw rectangle but it is disappearing when i stop the mouse dragging only.
Well, that's what the code is written to do. Di you write that code or copy it from somewhere without understanding it?

As I am new to graphics, can you please give me the code clearly which is need to be added or modified.

No, this is a forum, NotACodeMill <- link

What we will do is help you to understand what the code does, and make the changes yourself. Start by adding the code tags, and trying to understand what the code does. Refer to the API for java.awt.Rectangle to see what result is specified when you call the method you used, and the documentation for MouseListener to correctly understand when each method is called.


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4529
    
    5

Additionally, unless and until you reach a level of understanding the painting mechanism in Swing and AWT far above that of the average coder, do not use getGraphics() of a Component.
Prathyusha Tummepalli
Greenhorn

Joined: Sep 17, 2012
Posts: 3
sorry.. i do not know how to use these code tags..

As you have mentioned in the earlier thread, i was saving the reference of the rectangle.. still I am getting the problem. so I didnt get where i am doing the mistake..
I actually asked you to tell me where is the problem so that i can change it.
I wil once again go through the Rectangle API,

Thanks for your suggesion..
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4529
    
    5

What do you think line 40 in your posted code does, and when?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4529
    
    5

Also, I urge you to learn and follow the coding conventions, particularly in respect of consistent indents and vertical whitespace (blank lines).
Prathyusha Tummepalli
Greenhorn

Joined: Sep 17, 2012
Posts: 3
when I had the example it is displaying all the rectangles drawn. But i need only one rectangle and if I redraw another rectangle the first one must disapper so i thought it is saving the points of all the rectangle and i modified it.
 
Don't get me started about those stupid light bulbs.
 
subject: Selection rectangle on image