2012-08-16 62 views

回答

2

你應該告訴你希望它在新窗口中打開cmd.exe的:

Process pr = rt.exec("cmd.exe /c start"); 
0

從JDialog運行您的命令,運行後使用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); 
     } 
    } 
}); 
相關問題