swt interview questions
Top swt frequently asked interview questions
I know the following libraries for drawing charts in an SWT/Eclipse RCP application:
Which other libraries are there for drawing pretty charts with SWT? Or charts in Java generally? After all, you can always display an image...
Source: (StackOverflow)
I'm doing a WYSYWYG HTML5 editor With SWT by setting the contentEditable
attribute of the body tag to true
.
When I'm executing some commands like document.execCommand('bold')
, it works perfectly. But when I try to undo an operation with document.execCommand('undo')
nothing happens. I don't know if I have to set any undo manager or to do something like that. Can you help me please ?
Source: (StackOverflow)
Which are the reasons to choose the Eclipse Rich Client Platform as the base of my application, instead of just using SWT/JFace?
Source: (StackOverflow)
Is there a way to create native status bars in SWT like those found in Windows applications:

I have seen status bars simulated using labels, but I am more interested in a true solution.
Source: (StackOverflow)
I'm am looking for online tutorials/books, which assume a solid knowledge of OOP/Design patterns concepts and stress on differences (both conceptional and syntactical) between C++ and Java thus allowing for a rapid development in the latter.
Thank you very much in advance, appreciate your time.
Source: (StackOverflow)
I trying to learn swt, and I use maven for all my builds and eclipse for my IDE. When getting the swt jars out of the maven repository, I get:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no swt-pi-gtk-3034 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1709)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:100)
at org.eclipse.swt.internal.gtk.OS.<clinit>(OS.java:19)
at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:63)
at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:54)
at org.eclipse.swt.widgets.Display.<clinit>(Display.java:112)
at wenzlick.test.swt.main.Main.main(Main.java:30)
Has anyone successfully got a swt app to build and run using maven?
Edit: I did a little research and found the problem. look at my post below
Source: (StackOverflow)
In my Java application, when the main module is invoked, i start my SWT GUI in a separate thread. I need to perform some long opertations in the main thread and update the GUI thread. When I try to update the GUI thread from the main thread i.e. change a label text or something, i get a java.lang.NullPointerException
. From what I've read online is because SWT doesn't allow non-UI threads to update UI objects. How can I update the GUI thread from the main thread.
I've found some examples online but they all deal with the scenario in which the GUI runs in the main thread and long operation is in separate thread. My scenario is the total opposite.
Could someone tell me how I can update widgets in the GUI thread?
Source: (StackOverflow)
I have a mouse listener. It has some code to respond to mouseUp and mouseDown events. This works correctly.
However, as soon as I add a DragSource, my mouseDown event is no longer delivered -- until I release the mouse button!
This is trivial to reproduce - below is a simple program which contains a plain shell with just a mouse listener and a drag listener. When I run this (on a Mac), and I press and hold the mouse button, nothing happens - but as soon as I release the mouse button, I instantly see both the mouse down and mouse up events delivered. If I comment out the drag source, then the mouse events are delivered the way they should be.
I've searched for others with similar problems, and the closest I've found to an explanation is this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=26605#c16
"If you hook drag detect, the operating system needs to eat mouse events until it determines that you have either dragged or not."
However, I don't understand why that's true -- why must the operating system eat mouse events to determine if I have a drag or not? The drag doesn't start until I have a mouse -move- event with the button pressed.
More importantly: Can anyone suggest a workaround? (I tried dynamically adding and removing my drag source when the mouse is pressed, but then I couldn't get drag & drop to function properly since it never saw the initial key press - and I can't find a way to programmatically initiate a drag.)
Here's the sample program:
package swttest;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SwtTest {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.addMouseListener(new MouseListener() {
public void mouseUp(MouseEvent e) {
System.out.println("mouseUp");
}
public void mouseDown(MouseEvent e) {
System.out.println("mouseDown");
}
public void mouseDoubleClick(MouseEvent e) {
System.out.println("mouseDoubleClick");
}
});
DragSourceListener dragListener = new DragSourceListener() {
public void dragFinished(DragSourceEvent event) {
System.out.println("dragFinished");
}
public void dragSetData(DragSourceEvent event) {
System.out.println("dragSetData");
}
public void dragStart(DragSourceEvent event) {
System.out.println("dragStart");
}
};
DragSource dragSource = new DragSource(shell, DND.DROP_COPY | DND.DROP_MOVE);
dragSource.addDragListener(dragListener);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Source: (StackOverflow)
I have a simple Java SWT app in Java so far but the weird thing is when I try to launch a messagebox/alert box upon listening to an event fired by one of my own classes, I get an error saying "Invalid thread access".
My class event is fired and heard by the main class but it is when it has to show the MessageBox that the "Invalid thread access" error appear. I am trying to show the MessageBox in a function that consist of all the other codes that will create the SWT GUIs. This is how the function looks like:
public void createContents() {
Shell shell = new Shell();
//.....all the SWT GUI codes....
MessageBox msg = new MessageBox(shell, SWT.OK);
myClass.addEventListener(new MyClassEventClassListener() {
@Override
public void myClassEventHandler(MyClassEvent e) {
msg.setText("Hello");
msg.setMessage("Event fired!");
int result = msg.open();
}
});
}
These are the auxiliary functions together in the class.
<!-- language: lang-java -->
protected static Shell shell;
public static void main(String[] args) {
MyClass new myClass = new MyClass();
try {
SWTApp window = new SWTApp();
window.open();
} catch (Exception e) {
}
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
The error stack trace is as follows:
Exception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:4083)
at org.eclipse.swt.SWT.error(SWT.java:3998)
at org.eclipse.swt.SWT.error(SWT.java:3969)
at org.eclipse.swt.widgets.Display.error(Display.java:1249)
at org.eclipse.swt.widgets.Display.checkDevice(Display.java:755)
at org.eclipse.swt.widgets.Display.getShells(Display.java:2171)
at org.eclipse.swt.widgets.Display.setModalDialog(Display.java:4463)
at org.eclipse.swt.widgets.MessageBox.open(MessageBox.java:200)
Any help will be great.
Thanks!
Source: (StackOverflow)
Is it possible to create a focusable composite in SWT? I'm catching all keyboard events via Display filter, but there are some problems when the focus is on the tree or list - GTK+'s default action is to search in the contents of the control.
What I want to do is to mix SWT and AWT with focusable AWT component. I managed to make the AWT widget unfocusable and I added Display filter to make the AWT component receiving keyboard events (but not directly), even when it's not focused. But there are several problems when some SWT controls are focused - that's why I want to make composite focusable.
So my final question is: is it possible to make SWT composite focusable?
Source: (StackOverflow)
Situation:
- My RCP application uses XulRunner
- System has two installed PDF viewers (Acrobat, Gimp)
- Firefox has Gimp set as default viewer
- I want to make my SWT Browser composite in RCP application ignore default viewer and use Acrobat if it is installed
- If it is not, I want to use default viewer
Question:
- Can I achieve this by (temporarily) setting some XulRunner or System property in my application?
Source: (StackOverflow)
I have written a Java GUI using SWT. I package the application using an ANT script (fragment below).
<jar destfile="./build/jars/swtgui.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="org.swtgui.MainGui" />
<attribute name="Class-Path" value="." />
</manifest>
<fileset dir="./build/classes" includes="**/*.class" />
<zipfileset excludes="META-INF/*.SF" src="lib/org.eclipse.swt.win32.win32.x86_3.5.2.v3557f.jar" />
</jar>
This produces a single jar which on Windows I can just double click to run my GUI. The downside is that I have had to explicitly package the windows SWT package into my jar.
I would like to be able to run my application on other platforms (primarily Linux and OS X). The simplest way to do it would be to create platform specific jars which packaged the appropriate SWT files into separate JARs.
Is there a better way to do this? Is it possible to create a single JAR which would run on multiple platforms?
Source: (StackOverflow)
I've built a GUI using Swing and the MigLayout.
I am using Eclipse 4.2.2 (64-bit) on Windows 7 Ultimate.
Every time I click back into the window to edit my code, a popup comes up, then I'm prompted to restart Eclipse, and the Event log says the following:
org.eclipse.swt.SWTError: No more handles
at org.eclipse.swt.SWT.error(SWT.java:4387)
at org.eclipse.swt.SWT.error(SWT.java:4276)
at org.eclipse.swt.SWT.error(SWT.java:4247)
at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
at org.eclipse.swt.widgets.Control.createHandle(Control.java:704)
at org.eclipse.swt.widgets.Label.createHandle(Label.java:199)
at org.eclipse.swt.widgets.Control.createWidget(Control.java:744)
at org.eclipse.swt.widgets.Control.<init>(Control.java:112)
at org.eclipse.swt.widgets.Label.<init>(Label.java:101)
...
I'm attaching screenshots of the error messages.
Has anyone else encountered this bug with Eclipse? Do you know of a work-around or a fix?



Source: (StackOverflow)
I am writing an application in Java for the desktop using the Eclipse SWT library for GUI rendering. I think SWT helps Java get over the biggest hurdle for acceptance on the desktop: namely providing a Java application with a consistent, responsive interface that looks like that belonging to any other app on your desktop. However, I feel that packaging an application is still an issue.
OS X natively provides an easy mechanism for wrapping Java apps in native application bundles, but producing an app for Windows/Linux that doesn't require the user to run an ugly batch file or click on a .jar is still a hassle. Possibly that's not such an issue on Linux, where the user is likely to be a little more tech-savvy, but on Windows I'd like to have a regular .exe for him/her to run.
Has anyone had any experience with any of the .exe generation tools for Java that are out there? I've tried JSmooth but had various issues with it. Is there a better solution before I crack out Visual Studio and roll my own?
Edit: I should perhaps mention that I am unable to spend a lot of money on a commercial solution.
Source: (StackOverflow)