Java, run another application in foreground

前端 未结 4 1415
南笙
南笙 2021-01-12 19:39

I want run another application from java code.

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(\"cmd.exe\");

Process is launched, b

4条回答
  •  误落风尘
    2021-01-12 20:11

    Run your command from a JDialog and after running it, use toBack().

    final JDialog dlg = new javax.swing.JDialog(null, "test", JDialog.ModalityType.DOCUMENT_MODAL);
    dlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    JButton button = new JButton("Select Me");
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                java.awt.Desktop.getDesktop().open(
                        new java.io.File("/home/user/Downloads/jfreechart-1.0.13-US.pdf"));
                dlg.toBack();
            } catch (IOException e1) {
                throw new RuntimeException(e1);
            }
        }
    });
    

提交回复
热议问题