我今天刚刚开始使用SWT框架。我试图使用windows builder插件通过eclipse创建一个UI。代码就是这样的。
package com.teamcenter.rac.pse.revisionrules;
import com.teamcenter.rac.kernel.TCComponent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.SelectionDialog;
public class SetPackageContentsDialog
extends SelectionDialog
{
protected int result;
protected Shell shell;
private Text text;
private Table table;
/**
* Constructor
*
* @param shell2
* @param workPackageRevision
* @param b
* @param object
* @unpublished
*/
public SetPackageContentsDialog( Shell parentShell, TCComponent effectivityGrpRevision, boolean openByNameReqd,
SetMiscFieldsDialog dialog )
{
super( parentShell );
setTitle( "SWT Dialog" );
}
/**
* Method to bring up the SetMultiEndItemDialog
*
* @param shell Shell
* @unpublished
*/
public void post( Shell shell )
{
if( Thread.currentThread() == shell.getDisplay().getThread() )
{
open();
}
else
{
shell.getDisplay().asyncExec( new Runnable()
{
@Override
public void run()
{
open();
}
} );
}
}
/**
* Open the dialog.
*
* @return the result
*/
@Override
public int open()
{
createContents();
shell.open();
shell.layout();
Display display = getParentShell().getDisplay();
while( !shell.isDisposed() )
{
if( !display.readAndDispatch() )
{
display.sleep();
}
}
return result;
}
/**
* Create contents of the dialog.
*/
private void createContents()
{
shell = new Shell( getParentShell(), getShellStyle() );
shell.setSize( 461, 357 );
shell.setText( "New Aplooa" );
shell.setLayout( new GridLayout( 1, false ) );
Composite composite = new Composite( shell, SWT.NONE );
composite.setLayout( new GridLayout( 1, false ) );
GridData gd_composite = new GridData( SWT.LEFT, SWT.CENTER, false, false, 1, 1 );
gd_composite.widthHint = 445;
gd_composite.heightHint = 316;
composite.setLayoutData( gd_composite );
Composite composite_1 = new Composite( composite, SWT.NONE );
GridData gd_composite_1 = new GridData( SWT.LEFT, SWT.CENTER, false, false, 1, 2 );
gd_composite_1.widthHint = 434;
gd_composite_1.heightHint = 126;
composite_1.setLayoutData( gd_composite_1 );
Label lblContentType = new Label( composite_1, SWT.NONE );
lblContentType.setBounds( 7, 35, 71, 13 );
lblContentType.setText( "Content Type" );
Button btnItem = new Button( composite_1, SWT.RADIO );
btnItem.setBounds( 108, 33, 71, 16 );
btnItem.setText( "Item" );
Button btnDataset = new Button( composite_1, SWT.RADIO );
btnDataset.setBounds( 187, 33, 83, 16 );
btnDataset.setText( "Dataset" );
Label lblContentToAdd = new Label( composite_1, SWT.NONE );
lblContentToAdd.setBounds( 7, 61, 74, 13 );
lblContentToAdd.setText( "Content to Add" );
text = new Text( composite_1, SWT.BORDER );
text.setBounds( 108, 58, 162, 19 );
Combo combo = new Combo( composite_1, SWT.NONE );
combo.setBounds( 106, 90, 162, 21 );
Label lblRelationshipType = new Label( composite_1, SWT.NONE );
lblRelationshipType.setBounds( 7, 93, 90, 13 );
lblRelationshipType.setText( "Relationship Type" );
Button btnObn = new Button( composite_1, SWT.NONE );
btnObn.addSelectionListener( new SelectionAdapter()
{
@Override
public void widgetSelected( SelectionEvent e )
{
}
} );
btnObn.setBounds( 274, 52, 46, 30 );
btnObn.setText( "OBN" );
Button button = new Button( composite_1, SWT.NONE );
button.addSelectionListener( new SelectionAdapter()
{
@Override
public void widgetSelected( SelectionEvent e )
{
}
} );
button.setText( "Paste" );
button.setBounds( 326, 52, 46, 30 );
Button button_1 = new Button( composite_1, SWT.NONE );
button_1.addSelectionListener( new SelectionAdapter()
{
@Override
public void widgetSelected( SelectionEvent e )
{
}
} );
button_1.setText( "Clear" );
button_1.setBounds( 378, 52, 46, 30 );
Label lblWorkpackage = new Label( composite_1, SWT.NONE );
lblWorkpackage.setBounds( 7, 10, 71, 13 );
lblWorkpackage.setText( "WorkPackage" );
new Label( composite, SWT.NONE );
Composite composite_2 = new Composite( composite, SWT.NONE );
GridData gd_composite_2 = new GridData( SWT.LEFT, SWT.BOTTOM, false, false, 1, 1 );
gd_composite_2.heightHint = 156;
gd_composite_2.widthHint = 435;
composite_2.setLayoutData( gd_composite_2 );
table = new Table( composite_2, SWT.BORDER | SWT.FULL_SELECTION );
table.setBounds( 10, 10, 329, 97 );
table.setHeaderVisible( true );
table.setLinesVisible( true );
TableColumn tblclmnContent = new TableColumn( table, SWT.NONE );
tblclmnContent.setWidth( 101 );
tblclmnContent.setText( "Content" );
TableColumn tblclmnContentType = new TableColumn( table, SWT.NONE );
tblclmnContentType.setWidth( 113 );
tblclmnContentType.setText( "Content Type" );
TableColumn tblclmnRelationshipType = new TableColumn( table, SWT.NONE );
tblclmnRelationshipType.setWidth( 128 );
tblclmnRelationshipType.setText( "Relationship Type" );
Button button_2 = new Button( composite_2, SWT.NONE );
button_2.addSelectionListener( new SelectionAdapter()
{
@Override
public void widgetSelected( SelectionEvent e )
{
}
} );
button_2.setText( "ADD" );
button_2.setBounds( 366, 10, 46, 30 );
Button button_3 = new Button( composite_2, SWT.NONE );
button_3.setText( "REMOVE" );
button_3.setBounds( 366, 56, 46, 30 );
Button button_4 = new Button( composite_2, SWT.NONE );
button_4.addSelectionListener( new SelectionAdapter()
{
@Override
public void widgetSelected( SelectionEvent e )
{
}
} );
button_4.setText( "OK" );
button_4.setBounds( 143, 114, 46, 30 );
Button button_5 = new Button( composite_2, SWT.NONE );
button_5.addSelectionListener( new SelectionAdapter()
{
@Override
public void widgetSelected( SelectionEvent e )
{
}
} );
button_5.setText( "Cancel" );
button_5.setBounds( 229, 114, 46, 30 );
}
}
现在,我有两个基本查询。 1.我如何确保如果我进行调整大小[我在一个角落拖动对话框]所有组件都适当调整大小?和 2.如何确保此对话框不是模态的? [目前无法点击任何地方]。
我正在做一些研究,但任何指针肯定会有所帮助:)。
谢谢, 帕。