Does including javax.swing elements in a standalone exe cause it to crash?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Sruthi Ayloo
am 11 Jul. 2014
Bearbeitet: Sruthi Ayloo
am 11 Jul. 2014
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 Kommentare
Siehe auch
Kategorien
Mehr zu Call Java from MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!