Does including javax.swing elements in a standalone exe cause it to crash?

2 vues (au cours des 30 derniers jours)
Will
Will le 19 Fév 2014
Modifié(e) : Sruthi Ayloo le 11 Juil 2014
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.

Réponses (1)

Sruthi Ayloo
Sruthi Ayloo le 11 Juil 2014
Modifié(e) : Sruthi Ayloo le 11 Juil 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.

Catégories

En savoir plus sur Call Java from MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by