【问题标题】:How can I make window smaller than 100 pixels如何使窗口小于 100 像素
【发布时间】:2015-11-21 22:44:19
【问题描述】:

我尝试在屏幕底部制作一个状态栏,但窗口不能小于 100 像素。我正在处理 3.0.1。

我使用下面的代码

void setup() {
      surface.setResizable(true);
      surface.setSize(300, 20);
      surface.setLocation(displayWidth-300, displayHeight-50);
    }

void draw() {
  background(128);
}

有什么想法吗??

提前谢谢大家

J!

【问题讨论】:

    标签: processing


    【解决方案1】:

    如果去掉surface.setResizable(true);语句,可以看到画布是300x20,但是窗口不是:

    Processing 3.0 有很多 changes 包括重构窗口代码,之前依赖于 Java 的 AWT 包。

    浏览当前源代码,可以看到:

    static public final int MIN_WINDOW_WIDTH = 128;
    static public final int MIN_WINDOW_HEIGHT = 128;
    

    PSurface.java line 34 中定义 并一直使用PSurfaceAWT.java 来确保这些最小窗口尺寸。

    尝试访问 Surface 的画布 (println(surface.getNative());) 我可以将其列为processing.awt.PSurfaceAWT$SmoothCanvas,并且我可以看到一个看起来很有希望的SmoothCanvas class with a getFrame() method,但这似乎无法访问(即使它是一种公共方法公共类)。

    所以默认情况下,此时,我会说在 Processing 3.x 中将窗口大小调整为小于 128x128 是不行的。

    如果必须使用 Processing 3.x 和更小的窗口,则可以自己调整源代码并重新编译核心库,但这可能会在以后有多个带有多个版本的 Processing 核心库的 Processing 项目时给你带来麻烦.我不建议正常修改核心库。

    如果您的项目可以使用 Processing 2.x,则可以使窗口大小小于 100 像素:

    import java.awt.Dimension;
    
    int w = 300;
    int h = 20;
    int appBarHeight = 23;//this is on OSX, on Windows/Linux this may be different
    
    void setup() {
      size(w, h);
      frame.setResizable(true);
    }
    
    void draw() {
      if (frame.getHeight() != h+appBarHeight){//wait for Processing to finish setting up it's window dimensions (including minimum window dimensions)
        frame.setSize(w,h+appBarHeight);//set your dimensions
      }
      background(128);
    }
    

    【讨论】:

    • 谢谢!我和你有同样的想法。首先,我计划重建核心库,但现在我认为最好转到 2.x 版本。 3.x 版中的 frame.setUndecorated(true) 还提出了另一个问题,使我的面板没有窗框。
    • 您将无法将setUndecorated(true) 用于现有的处理框架,因为它已经可以显示(并且会抛出一个IllegalComponentStateException),但您可以创建自己的单独的java.awt.Frame 框架实例您可以 setUndecorate(true) 到,然后将 PApplet 组件添加到该组件(来自处理的现有框架)。更多详情请查看this answer
    猜你喜欢
    • 1970-01-01
    • 2013-11-10
    • 1970-01-01
    • 2020-11-21
    • 2012-11-16
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多