I've recently developed a SWT Standalone application with eclipse on my Mac OS X. The problem is now that I've finished, I wanted to export my application via the eclipse export to a Runnable Jar file. Everything works fine when I do it on my Mac OS X, but I also want to run the application on Ubuntu and other Unix based distributions.
So I thought I just import my eclipse project into the eclipse application on the respective OS and export the application again as a Runnable Jar. The problem is now that most of the features of my application don't work anymore ... Suddenly simple things like text boxes aren't displayed anymore and buttons don't work anymore.
The strange thing is when I start the application within my eclipse application everything works fine. I desperately tried to find a way of how to solve this problem, but I couldn't find anything yet. Hope someone can help me out here with this problem ...
Is it just a version problem or do I miss something else?
Here is an example code from one of my jface Dialogs that I can open from within my application:
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
// remaining imports omitted
public class ConnectionSettings extends Dialog {
/**
* The current status.
*/
private Text status;
// Other privates fields omitted.
#Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = (GridLayout) container.getLayout();
gridLayout.numColumns = 2;
// other initialisation of labels and text fields omitted
Group grpStatus = new Group(container, SWT.NONE);
grpStatus.setLayout(new GridLayout(1, false));
grpStatus.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2,
1));
grpStatus.setText("Status");
// This Text field isn't shown in the exported application
status = new Text(grpStatus, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP
| SWT.H_SCROLL | SWT.V_SCROLL);
status.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
// button omitted
return container;
}
// overriding this methods allows you to set the
// title of the custom dialog
#Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("Connection Settings");
}
#Override
protected Point getInitialSize() {
return new Point(450, 348);
}
That's how it looks like when I start my application within eclipse:
That's how it looks like when I start my exported application:
As you can see the text field is just not displayed while everything else works fine.
Related
I'm working in a GUI Java Application in Eclipse IDE. I'm using Window Builder to speed the UI design.
As a part of refactoring, I've changed the sequential and repetitive code to encapsulated versions in other packages, this breaks the "Design" view, but does not affect the application itself.
The problem is that any change made to the ui needs to be seen through the compiled app, (after compile and run the app I mean), and I need to manually relaunch app any time I make a change.
So, my question is:
Is there any plugin or tool that detects changes and automatically relaunches the application, as nodemon does in Nodejs applications.
Thanks in advance.
There is no such tool AFAIK. The next thing is to place the program in Debug mode add a refresh button to redraw the widget and hope for the best (the JVM might or might not be able to re-initialize your class).
Alternatively, you can create a class that monitors the filesystem for recompiles and then restarts your application.
All bleh...
The best tip I can give you is to redesign your application in a way that Windowbuilder can understand.
I assume you have refactored your UI into multiple modular parts. If your UI consists of e.g. a Customer Detail panel and a Customer List panel, you might want to develop each of these separately. This is something WB can handle fine.
Create your modular UI classes in such a way that WB can understand them by subclassing a Widget (preferably Composite). The class below can be added to the palette of Windowbuilder and dragged into your 'composite' application.
public class MyCustomerDetail extends Composite {
public MyCustomerDetail(Composite pParent, int pStyle) {
super(pParent, pStyle);
GridLayout gridLayout = new GridLayout(2, false);
setLayout(gridLayout);
Label label = new Label(this, SWT.NONE);
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
label.setText("Customer Name");
Text name = new Text(this, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
name.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
}
}
Don't make a POJO class with a GUI method. The following class cannot be handled by WB and is of bad taste altogether.
public class MyCustomerDetail {
public void createUI(Composite pParent) {
Label label = new Label(pParent, SWT.NONE);
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
label.setText("Customer Name");
Text name = new Text(pParent, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
name.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
}
}
I am looking to figure out how to set the text of a label on an external Application Window.
What I have:
I have two windows so far. The first one is the main application window that will appear when the user starts the program. The second window is another separate window that I have created specifically to display a custom error window.
The problem: I seem to be unable to call the label that I have created on the error window and set the text to something custom. Why? I want to be able to reuse this window many times! This window is aimed for things like error handling when there is invalid input or if the application cannot read/save to a file.
I was going to post screen shots but you need 10 rep for that. It would have explained everything better.
Here is the code for the label on the Error_dialog window:
Label Error_label = new Label(container, SWT.NONE);
Error_label.setBounds(10, 10, 348, 13);
Error_label.setText("Label I actively want to change!");
Here is the condition I would like to fire off when it is met:
if(AvailableSpaces == 10){
//Set the label text HERE and then open the window!
showError.open();
}
I have included this at the top of the class as well:
Error_dialog showError = new Error_dialog();
Just save the label as a field in your dialog class and add a 'setter' method. Something like:
public class ErrorDialog extends Dialog
{
private Label errorLabel;
... other code
public void setText(String text)
{
if (errorLabel != null && !errorLabel.isDisposed()) {
errorLabel.setText(text);
}
}
You will need to use your dialog like this:
ErrorDialog dialog = new ErrorDialog(shell);
dialog.create(); // Creates the controls
dialog.setText("Error message");
dialog.open();
Note: you should stick to the rules for Java variable names - they always start with lower case.
Further learn to use Layouts. Using setBounds will cause problems if the user is using different fonts.
It's late, I'm tired and I can't figure out why a simple popup panel instead of showing as it should, displays a label beneath my. For example:
|SOME CLICKABLE BUTTONS| | |
|SOME MORE OPTIONS | | SOME CONTENT |
|EVEN MORE OPTIONS | | |
|Please wait|
"Please wait" is the label as you can see is created like so in the:
#Override
public void onModuleLoad()
{ ...<snip> //creates
final PopupPanel popup = new PopupPanel(false, true);
popup.add(new Label("Please wait"));
popup.center();
RootPanel.get().add(popup);
Some things you should know:
I'm running this in development mode via Jetty. I'm using reflections without class literals to load my panels because I haven't come round to implementing the workaround using generators (and the application is rather large, so it needs splitting). Though I doubt these things are causing it problems.
Shouldn't upon load, a popup display? My overall goal is to have something which displays a loading gif everytime a new part of the application is loading.
Do not add your PopupPanel to a RootPanel.
Delete this line
RootPanel.get().add(popup);
and it will work.
I have a basic implementation of ElementListSelectionDialog, like following.
ElementListSelectionDialog dialog =
new ElementListSelectionDialog(shell, new LabelProvider());
dialog.setElements(new String[] { "Linux", "Mac", "Windows" });
dialog.setTitle("Which operating system are you using");
dialog.open();
The dialog opens well, but the list is empty, and when we type something in the search field, nothing happens.
I don't have any exception, I am under Eclipse Kepeler 4.3
I read somewhere that the selection dialog are directly reusable after 4.2 release of eclipse.
I deeply examined the ElementListSelectionDialog class, and I found that the problem comes from FiltredList not draw the elements provided via LabelProvider.
FilteredList list = new FilteredList(workArea,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL,new LabelProvider(),false,true,true);
list.setLayoutData(new GridData(GridData.FILL,
GridData.BEGINNING, true, false, 1, 1));
list.setFilter(""); //$NON-NLS-1$
list.setElements( new Object[] {"Item 1","Item 2","Item 3","Item"});
I don't know why it does not work for me, but one thing I am sure of is that it works fine in the Eclipse IDE.
I think I have no alternative, I must define my own Dialog based on a TableViewer
Has anyone succeeded to run a ElementListSelectionDialog in Eclipse 4 because it would be a shame not to use it, it's a Dialog to use as standrad
I have the same issue. Dialog updates it content via TableUpdateJob. Method schedule contains check against PlatformUI.isWorkbenchRunning(). So ever if you have custom RCP application you must start Workbench anyway or emulate this behavior.
I'm writing an SWT app using JOGL and the SWT/AWT bridge, and I'm trying to create multiple GLCanvas objects inside a Composite, which I'm then trying to put inside a tab. When it works, it looks like this:
But most of the time (about 75% perhaps, at random) it crashes with the following error message:
A fatal error has been detected by the Java Runtime Environment:
SIGSEGV (0xb) at pc=0x0024843a, pid=8618, tid=2345560944
JRE version: 6.0_22-b22
Java VM: OpenJDK Server VM (20.0-b11 mixed mode linux-x86 )
Derivative: IcedTea6 1.10.2
Distribution: Ubuntu 11.04, package 6b22-1.10.2-0ubuntu1~11.04.1
Problematic frame: C
[libpthread.so.0+0x843a] __pthread_mutex_lock+0x11a
I've also tried it with just one canvas instead of two, and I still get the same random crash. Occasionally, I get this error message instead:
java: tpp.c:63: __pthread_tpp_change_priority: Assertion `new_prio == -1 || (new_prio >= __sched_fifo_min_prio && new_prio <= __sched_fifo_max_prio)' failed.
Presumably there's a threading problem, maybe a race condition? Strangely enough, if I try to put the composite straight onto the shell instead of onto a tab, it works fine (or at least I haven't seen it crash).
The relevant bit of code looks like this:
tabFolder = new CTabFolder(shell, SWT.BORDER);
tabFolder.setSimple(false);
final Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayout(new FillLayout());
new VisualizerCanvas(composite, MeshFactory.loadObj("meshes/teapot_sealed.obj"));
new VisualizerCanvas(composite, MeshFactory.loadObj("meshes/duck.obj"));
final CTabItem item = new CTabItem(tabFolder, SWT.CLOSE);
item.setText("Test");
item.setImage(new Image(display, "img/test.jpg"));
item.setControl(composite);
The VisualizerCanvas constructor looks like this:
public VisualizerCanvas(Composite parent, Mesh mesh)
{
// Set up the canvas
GLProfile glProfile = GLProfile.getDefault();
GLCapabilities glCapabilities = new GLCapabilities(glProfile);
glCapabilities.setDoubleBuffered(true);
glCapabilities.setHardwareAccelerated(true);
glCanvas = new GLCanvas(glCapabilities);
glCanvas.addGLEventListener(this);
// Create the embedded AWT frame using the SWT/AWT bridge
Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.BORDER | SWT.NO_BACKGROUND);
composite.setLayout(new FillLayout());
Frame frame = SWT_AWT.new_Frame(composite);
frame.add(glCanvas);
// Add an animator to automatically update the canvas at 30fps
animator = new FPSAnimator(glCanvas, 30);
animator.add(glCanvas);
animator.start();
this.mesh = MeshFactory.normalizeMesh(mesh);
}
Am I doing something I shouldn't with SWT widgets/composites?
Finally solved the problem myself. Turns out it was indeed a race condition - I'm developing in Eclipse on Linux, and I need the following piece of code to prevent Linux window events getting lost:
static {
GLProfile.initSingleton(false);
}
I'd already put this in my VisualizerCanvas class, but not in my Visualizer class (the first piece of code). Presumably GLProfile and VisualizerCanvas were in a race to be loaded by the JVM, and GLProfile would sometimes win, resulting in a crash.