Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
I've created a J-Link application, which has a swing GUI. On click of a UI command button, I'm creating a part files (simulating File--> New Part). The same thing when wanted to simulate through a swing GUI in synchronous mode, the GUI gets created, but when I push the button in the GUI, the GUI hangs. Can any one help me in making the swing GUI work with PROE?
class MenuButtonListener extends DefaultUICommandActionListener {
public void OnCommand() {
try {
//This works
Session curSession = pfcGlobal.GetProESession();
Model tryModel = curSession.CreatePart("Testing");
tryModel.Display();
//This doesn't work
//How to make it work
csProe.StepToProeGui.createAndShowGUI();
} catch (Exception x) {
STEP_TO_PROE.printMsg("something wrong: " + x);
x.printStackTrace();
System.out.println("------------------------------------");
}
}
}
Solved! Go to Solution.
Ok Finally got it.
It is possible to call an PROE action from a swing GUI. Use the following code to test it.
Conclusion:
JFrame doesnt work in Synchronous J-Link application
JDialog works in Synchronous application by seeting the flag "setModal(true);"
/*
07-Feb-00 I-03-26 JCN $$1 Renamed and upgraded.
30-Jan-03 J-03-41 JCN $$2 Install test adds menu button.
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import com.ptc.cipjava.jxthrowable;
import com.ptc.pfc.pfcCommand.DefaultUICommandActionListener;
import com.ptc.pfc.pfcCommand.UICommand;
import com.ptc.pfc.pfcGlobal.pfcGlobal;
import com.ptc.pfc.pfcModel.Model;
import com.ptc.pfc.pfcSession.Session;
/**
* This class is used to start the jlink application in proe. The name of the
* class has to appear in the protk.dat under the java_app_class option.
**/
public class JlinkSwingTest {
// =========================================================================
/**
* This method is called by proe upon starting a jlink application This
* method gets the current session from the pfcGlobal(environment) Then it
* calls the install test with the session as the argument.
**/
public static void start() {
printMsg("Started");
try {
Session curSession = pfcGlobal.GetProESession();
UICommand cmd = curSession.UICreateCommand("MyFirstApp",
new MenuButtonListener());
curSession.UIAddButton(cmd, "File", null, "MyButton", "HelpTag",
"msg_JlinkSwingTest.txt");
}
catch (jxthrowable x) {
printMsg("something wrong: " + x);
x.printStackTrace();
System.out.println("------------------------------------");
}
}
// =========================================================================
/**
* This method is used for cleanup and etc... Called when the jlink
* application exits
*/
public static void stop() {
printMsg("Stop");
}
// =========================================================================
/**
* This method prints a string to the standard output.
*/
public static void printMsg(String msg) {
System.out.println("JLINK-Testing: " + msg);
}
}
/**
* @author XXXXXX
*
*/
class MenuButtonListener extends DefaultUICommandActionListener {
public void OnCommand() {
try {
JDialog f = new JDialog();
JButton jb = new JButton("Testing1");
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
Session curSession = pfcGlobal.GetProESession();
Model tryModel = curSession.CreatePart("Testing1");
tryModel.Display();
} catch (jxthrowable x) {
x.printStackTrace();
System.out
.println("------------------------------------");
}
}
});
f.add(jb);
f.pack();
f.setModal(true);
f.setVisible(true);
} catch (Exception x) {
x.printStackTrace();
System.out.println("------------------------------------");
}
}
}
Ok Finally got it.
It is possible to call an PROE action from a swing GUI. Use the following code to test it.
Conclusion:
JFrame doesnt work in Synchronous J-Link application
JDialog works in Synchronous application by seeting the flag "setModal(true);"
/*
07-Feb-00 I-03-26 JCN $$1 Renamed and upgraded.
30-Jan-03 J-03-41 JCN $$2 Install test adds menu button.
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import com.ptc.cipjava.jxthrowable;
import com.ptc.pfc.pfcCommand.DefaultUICommandActionListener;
import com.ptc.pfc.pfcCommand.UICommand;
import com.ptc.pfc.pfcGlobal.pfcGlobal;
import com.ptc.pfc.pfcModel.Model;
import com.ptc.pfc.pfcSession.Session;
/**
* This class is used to start the jlink application in proe. The name of the
* class has to appear in the protk.dat under the java_app_class option.
**/
public class JlinkSwingTest {
// =========================================================================
/**
* This method is called by proe upon starting a jlink application This
* method gets the current session from the pfcGlobal(environment) Then it
* calls the install test with the session as the argument.
**/
public static void start() {
printMsg("Started");
try {
Session curSession = pfcGlobal.GetProESession();
UICommand cmd = curSession.UICreateCommand("MyFirstApp",
new MenuButtonListener());
curSession.UIAddButton(cmd, "File", null, "MyButton", "HelpTag",
"msg_JlinkSwingTest.txt");
}
catch (jxthrowable x) {
printMsg("something wrong: " + x);
x.printStackTrace();
System.out.println("------------------------------------");
}
}
// =========================================================================
/**
* This method is used for cleanup and etc... Called when the jlink
* application exits
*/
public static void stop() {
printMsg("Stop");
}
// =========================================================================
/**
* This method prints a string to the standard output.
*/
public static void printMsg(String msg) {
System.out.println("JLINK-Testing: " + msg);
}
}
/**
* @author XXXXXX
*
*/
class MenuButtonListener extends DefaultUICommandActionListener {
public void OnCommand() {
try {
JDialog f = new JDialog();
JButton jb = new JButton("Testing1");
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
Session curSession = pfcGlobal.GetProESession();
Model tryModel = curSession.CreatePart("Testing1");
tryModel.Display();
} catch (jxthrowable x) {
x.printStackTrace();
System.out
.println("------------------------------------");
}
}
});
f.add(jb);
f.pack();
f.setModal(true);
f.setVisible(true);
} catch (Exception x) {
x.printStackTrace();
System.out.println("------------------------------------");
}
}
}