Questions tagged [swt]

SWT: The Standard Widget Toolkit is a user interface library for Java maintained by the Eclipse Foundation. SWT uses native widgets wherever possible to provide a look and feel consistent with the host platform. SWT is a third-party library (not included in the JVM) and applications that rely on it must distribute the appropriate library for each target operating system. Use this tag for questions about developing SWT based applications.

SWT: The Standard Widget Toolkit

SWT example

SWT is a user interface library for Java maintained by the Eclipse Foundation. SWT uses native widgets wherever possible to provide a look and feel consistent with the host platform.

SWT is a third-party library (not included in the JVM) and applications that rely on it must distribute the appropriate library for each target operating system.

Hello World

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;

public class HelloSWT {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    Label label = new Label(shell, SWT.NONE);
    label.setText("Hello, World!");
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}

Reference Documentation

6100 questions
26
votes
2 answers

How to hide an SWT composite so that it takes no space?

I need to hide a composite (and all children inside). Just setting setVisible(false) will keep the space of the composite. Composite outer = new Composite(parent, SWT.NONE); outer.setLayout(new GridLayout(1,false)); outer.setLayoutData(new…
yuris
  • 1,109
  • 4
  • 19
  • 33
26
votes
13 answers

Cannot load 64-bit SWT libraries on 32-bit JVM ( replacing SWT file )

I'm trying to debug this problem but not sure where exactly i need to replace SWT jar file for Eclipse. Current System Config: Eclipse Helios 3.6 - 32 Bit JDK 1.6 JVM - 32 Bit Windows 7 - 64 Bit Error Message: java.lang.UnsatisfiedLinkError:…
Mad-D
  • 4,479
  • 18
  • 52
  • 93
25
votes
2 answers

Running SWT based, cross-platform jar properly on a Mac

I have been working on a SWT-based project which is intended to be deployed as Java Web Start, and thus be used on multiple platforms. So far I have managed to tackle the exporting problem that arises due to the system-specific libraries SWT…
posdef
  • 6,498
  • 11
  • 46
  • 94
25
votes
6 answers

How do you build an SWT application with Maven

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…
Dave
  • 776
  • 1
  • 10
  • 25
25
votes
2 answers

Change just the font size in SWT

I need to use a larger font for one of the labels. label.setFont( new Font(display,"Arial", 14, SWT.BOLD ) ); but obviously Arial is not always the default font. I want to change just the size and keep everything else at default values. Can I do…
Tomas Andrle
  • 13,132
  • 15
  • 75
  • 92
21
votes
2 answers

SWT and AWT, what is the difference?

I understand that this question is rather general and kind of a holy war. Could you explain to me why SWT is successful when AWT is not, while these two frameworks use the same idea of native ui controls. What makes SWT different comparing to AWT?…
michael nesterenko
  • 14,222
  • 25
  • 114
  • 182
21
votes
4 answers

Why does an SWT Composite sometimes require a call to resize() to layout correctly?

Sometimes we encounter an SWT composite that absolutely refuses to lay itself out correctly. Often we encounter this when we have called dispose on a composite, and then replaced it with another; although it does not seem to be strictly limited to…
Jared
  • 25,520
  • 24
  • 79
  • 114
20
votes
6 answers

Easiest way to unit test SWT and Swing apps in a headless environment?

I'm looking to unit test some SWT and Swing code for a project I'm working on and the tests run fine as long as I'm running them from eclipse. As soon as I run them in my hudson environment it fails since hudson runs the tests in headless…
Allain Lalonde
  • 91,574
  • 70
  • 187
  • 238
20
votes
4 answers

SWT/JFace or Eclipse RCP?

Which are the reasons to choose the Eclipse Rich Client Platform as the base of my application, instead of just using SWT/JFace?
Giuseppe
  • 347
  • 2
  • 11
19
votes
1 answer

Making composite focusable in SWT

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…
m4tx
  • 4,139
  • 5
  • 37
  • 61
18
votes
5 answers

maven project: SWT 3.5 dependency: any official public repo?

Well, in short, I may need to grab new SWT version instead of 3.3 we're using for now. The project now has only this dependency and builds fine: org.eclipse.swt.win32.win32 x86
Anton Kraievyi
  • 4,182
  • 4
  • 26
  • 41
18
votes
11 answers

Libraries for pretty charts in SWT?

I know the following libraries for drawing charts in an SWT/Eclipse RCP application: Eclipse BIRT Chart Engine (Links to an article on how to use it) JFreeChart Which other libraries are there for drawing pretty charts with SWT? Or charts in Java…
Martin Klinke
  • 7,294
  • 5
  • 42
  • 64
17
votes
6 answers

What is the best OpenGL java binding?

I am trying to achieve better performance for my Java SWT application, and I just found out it is possible to use OpenGL in SWT. It seems there are more than one Java binding for OpenGL. Which one do you prefer? Note that I have never used OpenGL…
Nicolas
  • 2,321
  • 4
  • 21
  • 32
17
votes
5 answers

Why is subclassing not allowed for many of the SWT Controls?

I often find myself wanting to do it. It can be very useful when you want to store some useful information or extra states. So my question is, is there a very good/strong reason why this is forbidden? Thanks EDIT: Thanks a lot for all these answers.…
RAY
  • 6,810
  • 6
  • 40
  • 67
17
votes
2 answers

MouseDown events are not delivered until MouseUp when a Drag Source is present

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…
Tor Norbye
  • 9,062
  • 3
  • 29
  • 24