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

3 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Sruthi Ayloo
Sruthi Ayloo il 11 Lug 2014
Modificato: Sruthi Ayloo il 11 Lug 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.

Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by