Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT program doesn't run(I have written a program for temperature converter)
SWT program doesn't run [message #1708017] Fri, 11 September 2015 13:12 Go to next message
Amritansh Singh is currently offline Amritansh SinghFriend
Messages: 1
Registered: September 2015
Junior Member
Hi, here is the code which I have been trying to run
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class TemperatureConverter {
Display display = new Display();
Shell shell = new Shell(display);
Label fahrenheitLabel;
Label celsiusLabel;
Label MessageLabel;
Text fahrenheitValue;
Text celsiusValue;

public TemperatureConverter() {
shell.setText("Temperature Converter");
shell.setLayout(new RowLayout());
fahrenheitLabel = new Label(shell, SWT.NONE);
fahrenheitLabel.setText("Fahrenheit: ");
fahrenheitValue = new Text(shell, SWT.SINGLE | SWT.BORDER);
celsiusLabel = new Label(shell, SWT.NONE);
celsiusLabel.setText("Celsius: ");
celsiusValue = new Text(shell, SWT.SINGLE | SWT.BORDER);
MessageLabel = new Label(shell, SWT.BORDER);
GridData griddata = new GridData(GridData.FILL_BOTH);
griddata.horizontalSpan = 4;
ModifyListener listener = new ModifyListener() {

public void modifyText(ModifyEvent E) {
ValueChanged((Text) E.widget);
shell.setBounds(40, 30, 500, 600);;
while (!shell.isDisposed()) {
if (!display.readAndDispatch())

public void ValueChanged(Text text){
if(text == fahrenheitValue){
double fvalue = Double.parseDouble(text.getText());
double cvalue = (fvalue - 32) / 1.8;
MessageLabel.setText("Conversion Performer Successfully.");
} catch(NumberFormatException e){
celsiusValue.setText(" ");
MessageLabel.setText("Invalid Number Format " + text.getText());
} else {
Double cvalue = Double.parseDouble(text.getText());
Double fvalue = cvalue * 1.8 + 32;
MessageLabel.setText("Conversion Performed Successfully. ");
} catch(NumberFormatException e){
fahrenheitValue.setText(" ");
MessageLabel.setText("Invalid Number Format " + text.getText());
public static void main(String[] args) {
new TemperatureConverter();

I can run normal SWT programs like HelloSWT, creating a few buttons etc.
But this time I am getting these errors.

Exception in thread "main" java.lang.ClassCastException: org.eclipse.swt.layout.GridData cannot be cast to org.eclipse.swt.layout.RowData
at org.eclipse.swt.layout.RowLayout.layoutHorizontal(
at org.eclipse.swt.layout.RowLayout.layout(
at org.eclipse.swt.widgets.Composite.updateLayout(
at org.eclipse.swt.widgets.Composite.sendResize(
at org.eclipse.swt.widgets.Composite.setBounds(
at org.eclipse.swt.widgets.Decorations.setBounds(
at org.eclipse.swt.widgets.Shell.setBounds(
at org.eclipse.swt.widgets.Control.setBounds(
at org.eclipse.swt.widgets.Control.setBounds(
at demo1.TemperatureConverter.<init>(
at demo1.TemperatureConverter.main(

Please help me out as soon as possible..
Thanks in advance Smile Confused
Re: SWT program doesn't run [message #1708019 is a reply to message #1708017] Fri, 11 September 2015 13:14 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3068
Registered: July 2009
Senior Member
Moving this to the SWT forum.
Re: SWT program doesn't run [message #1708122 is a reply to message #1708019] Mon, 14 September 2015 05:40 Go to previous message
Niraj Modi is currently offline Niraj ModiFriend
Messages: 47
Registered: November 2013
Hi Amritansh,
You seems to be mixing RowLayout and GridLayout, suggest you to refer SWT example Snippets @
Previous Topic:programmatically fire Tab key press event
Next Topic:SWT maps event to wrong control
Goto Forum:

Current Time: Fri Mar 23 07:28:22 GMT 2018

Powered by FUDForum. Page generated in 0.01437 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software