Creating an offscreen frame in Java (or: how to avoid a blank menu on a Mac, when all application windows are closed)?

后端 未结 6 1863
囚心锁ツ
囚心锁ツ 2020-12-19 08:55

I am making a Mac application, and I want my menu bar to look right.

Any Mac user knows the menu bar should be in the top screen menu. Setting apple.laf.useSc

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-19 09:29

    This is a comment to trashgod's answer. It's too big so I have to move it here >.<


    More problems!

    I'm getting 2 errors:

    line 23: The method itemStateChanged(ItemEvent) of type new ItemListener(){} must override a superclass method

    line 50:The method run() of type new Runnable(){} must override a superclass method

    Any help? I've never encountered this before. I don't know what it means.

    EDIT: I have more problems! I need the offscreen window to be visible while it is offscreen for it to produce a menu to move to the screen menu bar. When I use the code

    offScreen = new JFrame("WTF?!  You can see me?");
    offScreen.setSize(400,300);
    offScreen.setLocation(0, java.awt.Toolkit.getDefaultToolkit().getScreenSize().height+50);
    System.out.println(offScreen.getLocation());
    offScreen.setVisible(true);
    System.out.println(offScreen.getLocation());
    

    I get the output:

    java.awt.Point[x=0,y=1100]
    java.awt.Point[x=0,y=961]
    

    It moves it back once it's made visible again!

    I've searched for ages and I can't find anything.

提交回复
热议问题