I am posting a sample code in which from LoginPage i have to go to a TestPage . I guess if i will achieve this, i can achieve the table. Right now, I am getting SWTException : Subclassing not allowed when i press enter key in the password field. Ideally , it should display a TestPage when i press "ENTER" hey in PASSWORD field. here are the files:
//LoginPagenew.java
package com.qwest.bpm.swt.designer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class LoginPageNew {
private Shell shell;
public LoginPageNew() {
super();
}
public static void main(String[] args) {
new LoginPageNew().initialize();
}
protected void checkSubClass() {
}
private void initialize(){
Display display = new Display();
shell = new Shell(display);
shell.setText("QBPM");
shell.setMaximized(true);
this.setupWidgets(display, shell);
shell.pack();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose();
}
private void setupWidgets(Display display, Shell shell){
final Display newDisplay = display;
FormLayout formlayout = new FormLayout();
shell.setLayout(formlayout);
Composite gridComp = new Composite(shell, SWT.NONE);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridComp.setLayout(gridLayout);
final Group group = new Group(gridComp, SWT.NONE);
group.setText("Credentials");
Label label1 = new Label(group, SWT.NONE);
label1.setText("User Name");
label1.setBounds(60, 60, 120, 20);
Text username = new Text(group, SWT.BORDER);
username.setBounds(200, 60, 120, 20);
Label label2 = new Label(group, SWT.NONE);
label2.setText("Password");
label2.setBounds(60, 90, 120, 20);
Text password = new Text(group, SWT.BORDER);
password.setEchoChar('*');
password.setBounds(200, 90, 120, 20);
password.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
// close the text editor and copy the data over
// when the user hits "ENTER"
if (e.character == SWT.CR) {
System.out.println("Enter is pressed kya");
TestPage form = new TestPage(LoginPageNew.this.shell);
form.show();
}
}});
Label label3 = new Label(group, SWT.NONE);
label3.setText("JNDI Server URL");
label3.setBounds(60, 120, 120, 20);
Text serverurl = new Text(group, SWT.BORDER);
serverurl.setText("t3://localhost:7001");
serverurl.setBounds(200, 120, 120, 20);
Label label4 = new Label(group, SWT.NONE);
label4.setText("Designer Server");
label4.setBounds(60, 150, 120, 20);
Text servername = new Text(group, SWT.BORDER);
servername.setText("com.qwest.bpm.designerserver.DesignerServerRemoteHome");
servername.setBounds(200, 150, 240, 20);
Label label5 = new Label(group, SWT.NONE);
label5.setText("Database");
label5.setBounds(60, 180, 120, 20);
Button database = new Button(group,SWT.RADIO);
database.setBounds(200, 180, 120, 20);
database.setText("MDW");
Button login = new Button(group,SWT.PUSH);
login.setBounds(150, 240, 120, 25);
login.setText("Login");
//login.addSelectionListener(page);
FormData formGrid = new FormData();
formGrid.top = new FormAttachment(0,120);
formGrid.left = new FormAttachment(0,150);
//formGrid.right = new FormAttachment(100,-10);
//formGrid.bottom = new FormAttachment(10);
gridComp.setLayoutData(formGrid);
}
}
//TestPage.java
package com.qwest.bpm.swt.designer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class TestPage extends Shell{
private Shell shell = null;
private Text firstName = null;
private Display display;
public TestPage(Shell arg0) {
this(arg0, SWT.APPLICATION_MODAL);
}
/**
* @param arg0
* @param arg1
*/
public TestPage(Shell arg0, int arg1) {
super(arg0, arg1);
}
protected void checkSubClass() {
}
public void show(){
shell = new Shell(display);
shell.setText("Edit");
shell.setLayout(new FillLayout());
//new Button(shell,SWT.PUSH).setText("Go");
this.initWidgets();
shell.pack();
shell.open();
//Display display = new Display();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
public void initWidgets(){
Group group = new Group(shell, SWT.NONE);
group.setText("Person");
GridLayout layout = new GridLayout();
layout.numColumns=2;
group.setLayout(layout);
new Label(group, SWT.SHADOW_OUT).setText("FirstName");
firstName = new Text(group, SWT.BORDER);
firstName.setText("Pankaj Bhomia");
}
}