Java文档上写
Returns a point which is the result of converting the argument, which is specified in coordinates relative to the receiver, to display relative coordinates.
我没太看懂。比如
button.addMouseListener(new MouseAdapter() {
public void mouseDown(final MouseEvent e) {
Point pt1 = button.toDisplay(0, 0);
Point pt2 = shell.toDisplay(e.x, e.y);
offset[0] = new Point(pt2.x - pt1.x, pt2.y - pt1.y);
}
});
pt1和pt2得到的都是什么东西?

解决方案 »

  1.   

    SWT里几个有用的方法 Control类:toControl ( Point  point) 
              Returns a point which is the result of converting the argument, which is specified in display relative coordinates, to coordinates relative to the receiver. //将 Point 由 Display 的绝对值转化为 Control 的相对值。toDisplay ( Point  point) 
              Returns a point which is the result of converting the argument, which is specified in coordinates relative to the receiver, to display relative coordinates.
    //将 Point 由 Control 的相对值转化为 Display 的绝对值。 Example: 
     Button button = new Button( s, SWT. BORDER );
     System. out .println( button.getLocation( ) ); //Point {0, 0}  
     System. out .println( button.toDisplay( button.getLocation( ) ) ); //Point {70, 89}  
     System. out .println( button.toControl( button.toDisplay( button.getLocation( ) ) ) ); //Point {0, 0}Device类:
    getDepth()
              Returns the bit depth of the screen, which is the number of bits it takes to represent the number of unique colors that the screen is currently capable of displaying.
    //拿到操作系统的颜色深度。 getDPI()
              Returns a point whose x coordinate is the horizontal dots per inch of the display, and whose y coordinate is the vertical dots per inch of the display.
    //拿到操作系统的DPI值。Example:
     System.out.println(Display.getDefault( ).getDepth( ));//32
     System.out.println(Display.getDefault( ).getDPI( ));//Point {96, 96} 
    本人不是很了解SWT,查到一点希望对楼主有用
      

  2.   

    toDisplay ( Point  point) 
              Returns a point which is the result of converting the argument, which is specified in coordinates relative to the receiver, to display relative coordinates.
    //将 Point 由 Control 的相对值转化为 Display 的绝对值。