Смотрите пример ниже. Вы можете скрыть его с помощью кода Java с помощью setVisible(false)
, как вы предложили, тогда будет вызываться событие appReOpened()
, когда пользователь нажимает на приложение в доке. Когда это произойдет, вы можете просто позвонить setVisible(true)
. Это должно имитировать поведение Command-H.
См. Также прокомментированный код для более уродливого решения.
public class Test extends JFrame implements ActionListener, com.apple.eawt.AppReOpenedListener {
public static void main(String[] args) {
Test frame = new Test();
JButton test = new JButton("test");
test.addActionListener(frame);
com.apple.eawt.Application app = com.apple.eawt.Application.getApplication();
app.addAppEventListener(frame);
frame.getContentPane().add(test);
frame.pack();
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent arg0) {
setVisible(false);
// try {
// Robot robot = new Robot();
// robot.keyPress(KeyEvent.VK_META);
// robot.keyPress(KeyEvent.VK_H);
// robot.keyRelease(KeyEvent.VK_H);
// robot.keyRelease(KeyEvent.VK_META);
// } catch (AWTException ex) {
// // TODO Auto-generated catch block
// ex.printStackTrace();
// }
}
@Override
public void appReOpened(AppReOpenedEvent arg0) {
setVisible(true);
}
}
Оберните JAR в связке приложений Mac OS X, обсуждали [здесь] (http://stackoverflow.com/a/14917990/230513) и [здесь] (http://stackoverflow.com/a/8956715/230513). – trashgod