aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Printing GUI current Coordinates in the GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Printing GUI current Coordinates in the GUI" Watch "Printing GUI current Coordinates in the GUI" New topic
Author

Printing GUI current Coordinates in the GUI

mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi All,

I am currently learning about GUI's and have created one that has four JButtons (right,left,up,down),the component moves 10 px in the directiion of the button that is clicked.
I would like to show the current coordinates in the GUI as it is moved with the buttons.

How would i go about that? Which component or method can i use for that?


Thanks
Mike
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8566

Component#getLocationOnScreen()


[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi Maneesh,

Thanks for the quick reply! I should have mentioned ia am using getX(), and getY() to find the current position of the component, i need to know how i can have those coordinates show within the GUI itself.
David Byron
Rancher

Joined: Jan 20, 2009
Posts: 169

mike ryan wrote:i need to know how i can have those coordinates show within the GUI itself.

The phrase "show within the GUI" is ambiguous.

One way to get the values would be to call .setTitle() on the JFrame itself and put your values in the title bar. That way, you could consult them even while laying out widgets within the frame.

Another way would be to set your values at text in a JLabel on a JPanel in the JFrame.

A different way would be to log the info and keep your GUI clean.


SCJD 6, Baroque Potion, Intermediate Java, G+
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi David,

Thanks for the tipps!! I will give it a try


Mike
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing GUI current Coordinates in the GUI
 
Similar Threads
JLabel is not shown
Superimposing image with grid
how to implement MVC?
JPanel Coordinates
JFrame positioning