
package com.deveshcodelab.examples.swt;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
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 SWTSnippet6 {
private static final String L_TEXT = "You have entered : ";
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, true));
Text text = new Text(shell, SWT.SINGLE | SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
text.setText("");
Label label = new Label(shell, SWT.BORDER);
label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
label.setText(L_TEXT);
text.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
label.setText(L_TEXT + text.getText());
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}