Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
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 30-Jan-13 5:53am
inch992

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
 
this.setShellStyle( SWT.ON_TOP);
 
That should keep the SWT in front layer.
  Permalink  

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

  Print Answers RSS
0 Mika Wendelius 161
1 Abhinav S 115
2 Peter Leow 110
3 Suvendu Shekhar Giri 100
4 Dave Kreskowiak 85
0 Sergey Alexandrovich Kryukov 8,513
1 OriginalGriff 6,526
2 Peter Leow 3,657
3 Zoltán Zörgő 3,426
4 Richard MacCutchan 2,417


Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100