简体   繁体   English

在Mac OS X中获取AWT框架的可绘制区域?

[英]Getting drawable area of an AWT frame in Mac OS X?

I have subclassed java.awt.Frame and have overridden the paint() method as I wish to draw the entire contents of the window manually. 我已经将java.awt.Frame子类化,并覆盖了paint()方法,因为我希望手动绘制窗口的全部内容。

However, on the graphics object, (0,0) corresponds to the upper left hand corner of the window inside the title bar decoration, not the first drawable pixel. 但是,在图形对象上,(0,0)对应于标题栏装饰窗口的左上角,而不是第一个可绘制像素。

Can I determine the co-ordinate of the first drawable pixel (ie, the height of the decoration) in a cross-platform manner, avoiding using a Mac OS X-specific fudge factor ? 我可以跨平台方式确定第一个可绘制像素的坐标(即装饰的高度),避免使用Mac OS X特定的软糖因子吗? Will I be forced to nest a Panel component in order to find the actual drawable area of the window? 我是否会被迫嵌套Panel组件以找到窗口的实际可绘制区域?

Here, my code fails to centre the blue square inside the paintable area of the window: 在这里,我的代码无法将蓝色方块置于窗口可绘制区域的中心:

@Override
public void paint (Graphics g) {
    g.setColor(Color.BLUE);
    g.setPaintMode();
    g.fillRect(30, 30, getWidth()-60, getHeight()-60);
}

You can find the frame insets by calling the getInsets method (defined in Container). 您可以通过调用getInsets方法(在Container中定义)来查找框架插入。 Frame insets are discussed at the top of the Frame API docs. 帧插入在Frame API文档的顶部进行了讨论。

So you want to paint the whole area and don't want a title bar at all? 所以你想画整个区域,根本不想要标题栏?

Assuming that you use JDk 1.4 (at least) then you can declare the frame to be "undecorated" (java.awt.Frame#setUndecorated(boolean)). 假设您使用JDk 1.4(至少),那么您可以将框架声明为“未修饰”(java.awt.Frame #setUndecorated(boolean))。 This way no title bar is created and therefore the frames-paintable area is the same as the frames-consumed area. 这样就不会创建标题栏,因此框架可绘制区域与帧消耗区域相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM