Does including javax.swing elements in a standalone exe cause it to crash?
1 次查看(过去 30 天)
显示 更早的评论
Suppose I have a set of codes to display a JFrame, a JPanel, and a JLabel. This works fine if I run it as a script file:
frame = javax.swing.JFrame('Test');
panel = javax.swing.JPanel();
label = javax.swing.JLabel('A label');
panel.add(label);
frame.add(panel);
frame.setDefaultCloseOperation(javax.swing.JFrame.HIDE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
The problem comes when I compile this as an exe file with the deploytool. It will compile and I can run the program, but the frame will show up for about 3 seconds or so then disappear. If I run from inside Matlab with !main.exe, there is no error message. Neither is there one if I run the executable from the Windows command prompt (same results -- shows for a few seconds and then crashes).
Any ideas what is going on here? I can compile other files just fine. Is the problem because I included the javax.swing elements?
Many thanks for your help.
0 个评论
回答(1 个)
Sruthi Ayloo
2014-7-11
编辑:Sruthi Ayloo
2014-7-11
You could add 'waitfor(frame)' at the end of your code and compile it using mcc with the -e flag for the windows console not to appear.
frame = javax.swing.JFrame('Test');
frame.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
panel = javax.swing.JPanel();
label = javax.swing.JLabel('A label');
panel.add(label);
frame.add(panel);
frame.pack();
frame.setVisible(true);
waitfor(frame);
This might resolve the issue. But, when the executable is run in MATLAB with the '!' operator, the control does not get returned to the MATLAB command line.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Java from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!