【问题标题】:Set resolution of a specific JFrame, not the computer's resolution设置特定 JFrame 的分辨率,而不是计算机的分辨率
【发布时间】:2013-06-20 00:38:06
【问题描述】:

在 Java 中是否有设置特定 JFrame 的分辨率而不是更改计算机的分辨率,这意味着如果我有大小为 100x100 的 JFrame,我可以让它左上角为 (0,0)右下角是(50,50)?这些点是 JFrame 内的坐标,例如在使用 Graphics (java.awt.Graphics) 时。

谢谢。

【问题讨论】:

    标签: java swing size jframe resolution


    【解决方案1】:

    Graphics2D 有一个缩放选项,请在Javadoc 中处理它。

    在你的情况下,就是这样:

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
    
        Graphics2D g2 = (Graphics2D)g;
        g2.scale(0.5, 0.5); // 50% x and 50% y
    
        // rest of rendering
    }
    

    【讨论】:

    • 直到您致电super.paintComponent ;)。缩放也不会影响事件(例如鼠标事件)
    • 无论如何要这样做并影响事件?
    • 查找JXLayer(或windows下的JLayer)
    • 将事件坐标相乘,方法与比例相同,x = evt.getX()*0.5 等。
    • 看看thisthis的例子
    猜你喜欢
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-24
    • 2023-04-07
    相关资源
    最近更新 更多