Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm using a commercial CAD/CAM system (NX, formally Unigraphics). This has an API that I can develop against (using Java). It allows me to create a JAR and execute it from inside the normal NX UI. Now I want to use SWT to create a dialog for the users to interact with.
I can create a Shell and pass it the default Display and the window pops up perfectly. The code I have so far is as follows:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

...
...


Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new RowLayout());

final Label label = new Label(shell, SWT.NONE);
label.setText("Hello, World!");

Button button = new Button(shell, SWT.PUSH);
button.setText("Create lines");
button.addSelectionListener(new SelectionListener() {
	@Override
	public void widgetDefaultSelected(SelectionEvent arg0) {
		createLines();
	}

	@Override
	public void widgetSelected(SelectionEvent event) {
		createLines();
	}
});

shell.pack();
label.pack();
button.pack();
shell.open();
while (!shell.isDisposed())
	if (!display.readAndDispatch())
		display.sleep();
display.dispose();
label.dispose();
button.dispose();

The SWT window that appears does not seem to be parented by the NX window, so if the user clicks in the NX window the SWT window disappears behind it.
What I think I need to do is get the Display (or maybe the Shell?) of the NX window and pass that to my Shell, but I can't seem to find out how to do that.
I've Googled till my head hurts but all the "re-parenting", "set shell", "make modal" searches all talk about child Shells inside an existing parent SWT Shell.
Anyone got any ideas if this is even possible?
Posted

1 solution

I don't know if the NX System will even recognize the running shell of your SWT.

What you can do is to place the SWT part topmost:

Java
this.setShellStyle( SWT.ON_TOP);


That should keep the SWT in front layer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900