SWT文本组件水平对齐

时间:2013-12-11 11:58:06

标签: java swt

我需要目录的textarea和朝向小组右侧的进程按钮,但我无法得到它......任何对此的帮助对我来说都很棒.... 浏览器按钮后我仍然在右端(即)得到一些空间....我需要摆脱这个空间,不知道我哪里出错了....

代码:

                                          Label label = new Label(DGroup, SWT.NONE);
    final GridData gd_Label = new GridData();
            gd_Label.horizontalIndent = 20;
            label .setLayoutData(gd_Label);
            label.setText("Directory:");
            label.setToolTipText("The directory to write files to");

            directoryText = new StyledText(DGroup, SWT.BORDER );

            directoryText.addSelectionListener(new SelectionAdapter()
            {
                @Override
                public void widgetSelected(final SelectionEvent e)
                {
                    enableDisableControls();
                }
            });



    GridData gd_DirectoryText = new GridData();
    gd_DirectoryText.horizontalAlignment = SWT.FILL;
    gd_DirectoryText.grabExcessHorizontalSpace = true;
    gd_DirectoryText.horizontalSpan = 1;
    directoryText.setLayoutData(gd_DirectoryText);

    directoryText .setLayoutData(gd_DirectoryText );



            final Button browseDirectoryButton = new Button(DGroup, SWT.NONE);
            browseDirectoryButton.setToolTipText("Select the directory the connector will write files to.");
                                               final GridData gd_browseDirectoryButton = new GridData();
            browseDirectoryButton.setLayoutData(gd_browseDirectoryButton );
            browseDirectoryButton.setText("...");

整个区块:

protected void setControls(Composite parent)
{
    OptionGroup = new Group(this, SWT.None);
    OptionGroup.setLayout(new GridLayout(1,false));
    GridData gridData=new GridData(GridData.FILL_HORIZONTAL);
    gridData.heightHint=400;
    OptionGroup.setLayoutData(gridData);

    ScrolledComposite scrolledPane=new ScrolledComposite(OptionGroup,SWT.V_SCROLL);
    scrolledPane.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite projectPane=new Composite(scrolledPane,SWT.NONE);
    projectPane.setLayout(new GridLayout(2,false)); 

    DGroup = new Group(projectPane, SWT.None);
    DGroup.setLayout(new GridLayout(3,true));
    GridData gData=new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
    DGroup.setLayoutData(gData);




    Label label = new Label(DGroup, SWT.NONE);
    final GridData gd_Label = new GridData();
            gd_Label.horizontalIndent = 20;
            label .setLayoutData(gd_Label);
            label.setText("Directory:");
            label.setToolTipText("The directory to write files to");

            directoryText = new StyledText(DGroup, SWT.BORDER );

            directoryText.addModifyListener(modifyListener);

            try
            {
                directoryNameProposal = new ParameterProposals(directoryText);
            }
            catch (Exception e1)
            {

            }

            directoryText.addSelectionListener(new SelectionAdapter()
            {
                @Override
                public void widgetSelected(final SelectionEvent e)
                {
                    enableDisableControls();
                }
            });


    GridData gd_DirectoryText = new GridData();
    gd_DirectoryText.horizontalAlignment = SWT.FILL;
    gd_DirectoryText.grabExcessHorizontalSpace = true;
    gd_DirectoryText.horizontalSpan = 1;
    directoryText.setLayoutData(gd_DirectoryText);

    directoryText .setLayoutData(gd_DirectoryText );



            final Button browseDirectoryButton = new Button(DGroup, SWT.NONE);
            browseDirectoryButton.setToolTipText("Select the directory the connector will write files to.");
                                               final GridData gd_browseDirectoryButton = new GridData();
            browseDirectoryButton.setLayoutData(gd_browseDirectoryButton );
            browseDirectoryButton.setText("...");

            browseDirectoryButton.addSelectionListener(new SelectionAdapter()
            {
                @Override
                public void widgetSelected(final SelectionEvent e)
                {
                    String dir = doBrowse(browseDirectoryButton.getToolTipText(), "Select Directory");
                    if (dir != null)
                    {
                        directoryText.setText(dir);
                    }
                }
            });


    createDirectory = new Button(projectPane, SWT.CHECK);
    createDirectory.setToolTipText("Indicates whether directoty will be created if it does not exist.");
    createDirectory.setText("Create Directory");
    createDirectory.setSelection(false);
    createDirectory.addSelectionListener(new SelectionAdapter()
    {
        @Override
        public void widgetSelected(final SelectionEvent e)
        {
            enableDisableControls();
        }
    });



    label = new Label(projectPane, SWT.NULL);
    label.setText("File Name:");
    label.setToolTipText("The name of the file to write to");

    fileNameText = new StyledText(projectPane, SWT.BORDER | SWT.SINGLE);
    fileNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    fileNameText.addModifyListener(modifyListener);

    try
    {
        fileNameProposal = new ParameterProposals(fileNameText);
    }
    catch (Exception e1)
    {

    }

    new Label(this, SWT.NONE);

    label = new Label(projectPane, SWT.NULL);
    label.setText("Username:");

    fileUsername = new StyledText(projectPane, SWT.BORDER | SWT.SINGLE);
    fileUsername.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    fileUsername.addModifyListener(modifyListener);
    fileUsername.setToolTipText("The username to access the file.");    

    new Label(this, SWT.NONE);

    label = new Label(projectPane, SWT.NULL);
    label.setText("Encoding:");

    encodingCombo = new CharsetCombo(projectPane, SWT.READ_ONLY);
    encodingCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    encodingCombo.addModifyListener(modifyListener);
    encodingCombo.setToolTipText("The character set used to encode data.");
    new Label(this, SWT.NONE);

    appendButton = new Button(projectPane, SWT.CHECK);
    appendButton.setToolTipText("Indicates whether data is to be appended to the file.  If the file exists, and Append is false, the file is overwritten.  If the file exists and Append is true, the data is appended to the file.  Otherwise, a new file is created.");
    appendButton.setText("Append to file");
    appendButton.setSelection(false);
    appendButton.addSelectionListener(new SelectionAdapter()
    {
        @Override
        public void widgetSelected(final SelectionEvent e)
        {

            if (appendButton.getSelection() && useTempFileButton.getSelection())
            {
                useTempFileButton.setSelection(false);
            }
            enableDisableControls();
        }
    });
    new Label(this, SWT.NONE);
    new Label(this, SWT.NONE);



    fileOptionGroup = new Group(projectPane, SWT.NONE);
    fileOptionGroup.setText("If the file exists");
    fileOptionGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    fileOptionGroup.setLayout(new GridLayout());

    final GridLayout gl_fileOptionGroup = new GridLayout();
    gl_fileOptionGroup.numColumns = 3;
    fileOptionGroup.setLayout(gl_fileOptionGroup);

    btnOverwrite = new Button(fileOptionGroup, SWT.RADIO);
    btnOverwrite.setLayoutData(new GridData());
    btnOverwrite.setToolTipText("Overwirte to an existing file");
    btnOverwrite.setText("Overwrite");
    btnOverwrite.setSelection(true);

    btnSkip = new Button(fileOptionGroup, SWT.RADIO);
    btnSkip.setLayoutData(new GridData());
    btnSkip.setToolTipText("Skip to save the file");
    btnSkip.setText("Skip");
    btnSkip.setSelection(false);

    btnRetry = new Button(fileOptionGroup, SWT.RADIO);
    btnRetry.setLayoutData(new GridData());
    btnRetry.setToolTipText("Retry to get the file");
    btnRetry.setText("Retry");
    btnRetry.addSelectionListener(new SelectionAdapter()
    {
        @Override
        public void widgetSelected(final SelectionEvent e)
        {
            enableDisableControls();
        }
    });

    retryOptionGroup = new Group(projectPane, SWT.NONE);
    retryOptionGroup.setText("Retry options");
    final GridData gd_retryOptionGroup = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
    retryOptionGroup.setLayoutData(gd_retryOptionGroup);
    retryOptionGroup.setLayout(new GridLayout());
    final GridLayout gl_retryOptionGroup = new GridLayout();
    gl_retryOptionGroup.numColumns = 2;
    retryOptionGroup.setLayout(gl_retryOptionGroup);

    sendRetriesLabel = new Label(retryOptionGroup, SWT.NULL);
    final GridData gd_sendRetriesLabel = new GridData();
    gd_sendRetriesLabel.horizontalIndent = 20;
    gd_sendRetriesLabel.horizontalAlignment = SWT.FILL;
    sendRetriesLabel.setLayoutData(gd_sendRetriesLabel);
    sendRetriesLabel.setText("Send Attempts:");

    sendRetriesSpin = new Spinner(retryOptionGroup, SWT.BORDER | SWT.SINGLE);
    sendRetriesSpin.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    sendRetriesSpin.setToolTipText("The number of times to attempt to send a message to the external resource before failing with an error.");

    sendRetriesSpin.setValues(5, 1, Spinner.LIMIT, 0, 1, 10);

    retryIntervalLabel = new Label(retryOptionGroup, SWT.NULL);
    retryIntervalLabel.setText("Interval between Attempts (ms):");
    final GridData gd_retryIntervalText = new GridData();
    gd_retryIntervalText.horizontalIndent = 20;
    gd_retryIntervalText.horizontalAlignment = SWT.FILL;
    retryIntervalLabel.setLayoutData(gd_retryIntervalText);

    sendRetryIntervalText = new StyledText(retryOptionGroup, SWT.BORDER | SWT.SINGLE);
    sendRetryIntervalText.setToolTipText("The time interval in milliseconds the connector waits between message send attempts.");
    sendRetryIntervalText.setText("10000");
    sendRetryIntervalText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    new Label(this, SWT.NONE);


    useTempFileButton = new Button(projectPane, SWT.CHECK);
    useTempFileButton.setToolTipText("Indicates if the data is to be gathered in a temporary file first and renamed when writing is complete.");
    useTempFileButton.setText("Use temporary file");
    useTempFileButton.setSelection(false);
    useTempFileButton.addSelectionListener(new SelectionAdapter()
    {
        @Override
        public void widgetSelected(final SelectionEvent e)
        {
            enableDisableControls();
        }
    });
    new Label(this, SWT.NONE);

    useTemporaryFileGroup = new Group(projectPane, SWT.NONE);
    final GridData gd_useTemporaryFileGroup = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
    useTemporaryFileGroup.setLayoutData(gd_useTemporaryFileGroup);
    useTemporaryFileGroup.setLayout(new GridLayout());
    final GridLayout gl_useTemporaryFileGroup = new GridLayout();
    gl_useTemporaryFileGroup.numColumns = 2;
    useTemporaryFileGroup.setLayout(gl_useTemporaryFileGroup);

    tempFilePrefixLabel = new Label(useTemporaryFileGroup, SWT.NULL);
    final GridData gd_tempFilePrefixLabel = new GridData();
    gd_tempFilePrefixLabel.horizontalIndent = 20;
    gd_tempFilePrefixLabel.horizontalAlignment = SWT.FILL;
    tempFilePrefixLabel.setLayoutData(gd_tempFilePrefixLabel);
    tempFilePrefixLabel.setText("Temp file prefix:");

    tempFilePrefixText = new StyledText(useTemporaryFileGroup, SWT.BORDER | SWT.SINGLE);
    tempFilePrefixText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    tempFilePrefixText.addModifyListener(modifyListener);
    tempFilePrefixText.setToolTipText("The prefix string to be used in generating the temp file's name; must be at least three characters long");
    tempFilePrefixText.setText(IFileConnectorProfileConstants.DEFAULT_TEMPFILE_PREFIX);
    try
    {
        tempFilePrefixProposal = new ParameterProposals(tempFilePrefixText);
    }
    catch (Exception e1)
    {

    }
    tempFileSuffixLabel = new Label(useTemporaryFileGroup, SWT.NULL);
    tempFileSuffixLabel.setText("Temp file suffix:");
    final GridData gd_tempFileSuffixLabel = new GridData();
    gd_tempFileSuffixLabel.horizontalIndent = 20;
    gd_tempFileSuffixLabel.horizontalAlignment = SWT.FILL;
    tempFileSuffixLabel.setLayoutData(gd_tempFileSuffixLabel);

    tempFileSuffixText = new StyledText(useTemporaryFileGroup, SWT.BORDER | SWT.SINGLE);
    tempFileSuffixText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    tempFileSuffixText.addModifyListener(modifyListener);
    tempFileSuffixText.setToolTipText("The suffix string to be used in generating the temp file's name");
    tempFileSuffixText.setText(IFileConnectorProfileConstants.DEFAULT_TEMPFILE_SUFFIX);
    try
    {
        tempFileSuffixProposal = new ParameterProposals(tempFileSuffixText);
    }
    catch (Exception e1)
    {

    }
    new Label(this, SWT.NONE);
    fileContentsLabel = new Label(projectPane, SWT.NULL);
    fileContentsLabel.setText("Replace an empty message with:");
    fileContentsLabel.setLayoutData(new GridData());
    fileContentsText = new StyledText(projectPane, SWT.BORDER | SWT.SINGLE);
    fileContentsText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    fileContentsText.setToolTipText("The default contents to be used when receiving contents is null");

    final Group archiveModeGroup = new Group(projectPane, SWT.NONE);
    archiveModeGroup.setText("Archive Selection");
    final GridData gd_archiveModeGroup = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
    gd_archiveModeGroup.heightHint = 141;
    archiveModeGroup.setLayoutData(gd_archiveModeGroup);
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    archiveModeGroup.setLayout(gridLayout);
    noneButton = new Button(archiveModeGroup, SWT.RADIO);
    noneButton.setSelection(true);
    noneButton.addSelectionListener(new SelectionAdapter()
    {
        @Override
        public void widgetSelected(final SelectionEvent e)
        {
            enableDisableControls();
        }
    });
    noneButton.setToolTipText("Only use this mode to test the configuration.  This is not suitable for production operation.");
    final GridData gd_noneButton = new GridData();
    gd_noneButton.horizontalIndent = 10;
    noneButton.setLayoutData(gd_noneButton);
    noneButton.setText("None");
    new Label(archiveModeGroup, SWT.NONE);
    new Label(archiveModeGroup, SWT.NONE);

    deleteButton = new Button(archiveModeGroup, SWT.RADIO);
    deleteButton.addSelectionListener(new SelectionAdapter()
    {
        @Override
        public void widgetSelected(final SelectionEvent e)
        {
            enableDisableControls();
        }
    });
    deleteButton.setToolTipText("Delete a file after it is processed.");
    final GridData gd_deleteButton = new GridData();
    gd_deleteButton.horizontalIndent = 10;
    deleteButton.setLayoutData(gd_deleteButton);
    deleteButton.setText("Delete");
    new Label(archiveModeGroup, SWT.NONE);
    new Label(archiveModeGroup, SWT.NONE);

    backupButton = new Button(archiveModeGroup, SWT.RADIO);
    backupButton.addSelectionListener(new SelectionAdapter()
    {
        @Override
        public void widgetSelected(final SelectionEvent e)
        {
            enableDisableControls();
            handleValidationListeners(null);
        }
    });

    backupButton.setToolTipText("Move a file to the Archive directory after it is processed.");
    final GridData gd_backupButton = new GridData();
    gd_backupButton.horizontalIndent = 10;
    backupButton.setLayoutData(gd_backupButton);
    backupButton.setText("Backup");
    new Label(archiveModeGroup, SWT.NONE);
    new Label(archiveModeGroup, SWT.NONE);

    archiveDirectoryLabel = new Label(archiveModeGroup, SWT.NONE);
    final GridData gd_archiveDirectoryLabel = new GridData();
    gd_archiveDirectoryLabel.horizontalIndent = 20;
    archiveDirectoryLabel.setLayoutData(gd_archiveDirectoryLabel);
    archiveDirectoryLabel.setText("Archive Directory:");

    archiveDirectoryText = new StyledText(archiveModeGroup, SWT.BORDER);
    archiveDirectoryText.addModifyListener(modifyListener);
    try
    {
        archiveDirectoryProposal = new ParameterProposals(archiveDirectoryText);
    }
    catch (Exception e1)
    {

    }
    archiveDirectoryText.setToolTipText("The directory to move files to after they are processed.");
    final GridData gd_archiveDirectoryText = new GridData(SWT.FILL, SWT.CENTER, true, false);
    archiveDirectoryText.setLayoutData(gd_archiveDirectoryText);
    browseArchiveDirectoryButton = new Button(archiveModeGroup, SWT.NONE);
    browseArchiveDirectoryButton.setToolTipText("Select the directory the listener will move files to after they are processed.");
    final GridData gd_browseArchiveDirectoryButton = new GridData();
    browseArchiveDirectoryButton.setLayoutData(gd_browseArchiveDirectoryButton);
    browseArchiveDirectoryButton.setText("...");        

    new Label(this, SWT.NONE);
    browseArchiveDirectoryButton.addSelectionListener(new SelectionAdapter()
    {
        @Override
        public void widgetSelected(final SelectionEvent e)
        {
            String dir = doBrowse(browseArchiveDirectoryButton.getToolTipText(), "Select Archive Directory");
                if (dir != null)
                {
                    archiveDirectoryText.setText(dir);
                }

        }
    });

    archiveFileNameLabel = new Label(archiveModeGroup, SWT.NULL);
    archiveFileNameLabel.setText("Archieve FileName:");
    archiveFileNameLabel.setToolTipText("The name of the file to write to");

    archivefileNameText = new StyledText(archiveModeGroup, SWT.BORDER | SWT.SINGLE);
    archivefileNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    archivefileNameText.addModifyListener(modifyListener);

    try
    {
        archivefileNameProposal = new ParameterProposals(archivefileNameText);
    }
    catch (Exception e1)
    {

    }

    enableDisableControls();

    new Label(this, SWT.NONE);
    recordDelimiterLabel = new Label(projectPane, SWT.NONE);
    recordDelimiterLabel.setText("Record Delimiter:");
    recordDelimiterLabel.setLayoutData(new GridData());

    recordDelimiterText = new Text(projectPane, SWT.BORDER | SWT.SINGLE);
    // recordDelimiterText.setText("<CR><LF>");
    recordDelimiterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    recordDelimiterText.setToolTipText("Put delimiter if needed, <CR><LF> for carriage return.");
    new Label(this, SWT.NONE);

    recordLengthLabel = new Label(projectPane, SWT.NONE);
    recordLengthLabel.setText("Record Length:");
    recordLengthLabel.setLayoutData(new GridData());

    recordLengthSpinner = new Spinner(projectPane, SWT.BORDER);
    recordLengthSpinner.setMaximum(Integer.MAX_VALUE);
    recordLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    recordLengthSpinner.setToolTipText("Delimited by a specified length");
    new Label(this, SWT.NONE);
    scrolledPane.setContent(projectPane);
    scrolledPane.setExpandVertical(true);
    scrolledPane.setExpandHorizontal(true);
    scrolledPane.setMinSize(projectPane.computeSize(SWT.DEFAULT,SWT.DEFAULT));
    enableDisableControls();
}

感谢

0 个答案:

没有答案