The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > The Screen  [2 examples]

e865. Converting Between Component and Screen Coordinates

This example demonstrates how to convert a coordinate within a component to a coordinate on the screen and visa versa.
    // Convert a coordinate relative to a component's bounds to screen coordinates
    Point pt = new Point(component.getLocation());
    SwingUtilities.convertPointToScreen(pt, component);
    
    // Convert a coordinate on a screen to a coordinate relative to a component's bounds
    SwingUtilities.convertPointFromScreen(pt, component);

 Related Examples
e864. Capturing a Screen Shot

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JFrame, JWindow, JDialog    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSpinner    JSplitPane    JTabbedPane    JToolBar    Keystrokes and Input Maps    Layout    Look and Feel    Menus    Progress Monitor    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.