org.eclipse.swt.widgets.Button.setText()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(14.3k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中org.eclipse.swt.widgets.Button.setText()方法的一些代码示例,展示了Button.setText()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Button.setText()方法的具体详情如下:
包路径:org.eclipse.swt.widgets.Button
类名称:Button
方法名:setText

Button.setText介绍

[英]Sets the receiver's text.

This method sets the button label. The label may include the mnemonic character but must not contain line delimiters.

Mnemonics are indicated by an '&' that causes the next character to be the mnemonic. When the user presses a key sequence that matches the mnemonic, a selection event occurs. On most platforms, the mnemonic appears underlined but may be emphasized in a platform specific manner. The mnemonic indicator character '&' can be escaped by doubling it in the string, causing a single '&' to be displayed.

Note that a Button can display an image and text simultaneously on Windows (starting with XP), GTK+ and OSX. On other platforms, a Button that has an image and text set into it will display the image or text that was set most recently.

Also note, if control characters like '\n', '\t' etc. are used in the string, then the behavior is platform dependent.
[中]设置接收者的文本。
此方法设置按钮标签。标签可以包含助记字符,但不能包含行分隔符。
助记符由“&”表示,它使下一个字符成为助记符。当用户按下与助记符匹配的键序列时,会发生选择事件。在大多数平台上,助记符带下划线,但可能以特定于平台的方式强调。助记指示符“&”可以通过在字符串中加倍来转义,从而显示单个“&”。
请注意,按钮可以在Windows(从XP开始)、GTK+和OSX上同时显示图像和文本。在其他平台上,设置了图像和文本的按钮将显示最近设置的图像或文本。
另外请注意,如果字符串中使用了诸如“\n”、“t”等控制字符,则该行为取决于平台。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * @param style
 *          style to use.
 * @param text
 *          text to set.
 * @return new button.
 */
public Button createButton( final int style, final String text ) {
 final Button button = new Button( this.shell, style );
 button.setText( text );
 return button;
}

代码示例来源:origin: pentaho/pentaho-kettle

private void setCloseButton() {
 closeButton = new Button( shell, SWT.PUSH );
 closeButton.setText( BaseMessages.getString( PKG, "System.Button.Close" ) );
 FormData fdbutton = new FormData();
 fdbutton.right = new FormAttachment( 100, 0 ); //Button should below the link and separated by 30
 fdbutton.top = new FormAttachment( link, padding );
 fdbutton.height = padding;
 closeButton.setLayoutData( fdbutton );
 props.setLook( closeButton );
 // Add listeners
 closeButton.addListener( SWT.Selection, new Listener() {
  public void handleEvent( Event e ) {
   close();
  }
 } );
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * build Ok Button.
 */
protected void buildOkButton() {
 Button ok = new Button( this.dialog, SWT.PUSH );
 ok.setText( BaseMessages.getString( PKG, "TeraFastDialog.About.Plugin.Close" ) );
 GridData grdData = new GridData( GridData.HORIZONTAL_ALIGN_CENTER );
 grdData.horizontalSpan = 2;
 grdData.verticalIndent = DEFAULT_INDENT;
 grdData.horizontalIndent = DEFAULT_INDENT;
 ok.setLayoutData( grdData );
 ok.addListener( SWT.Selection, new Listener() {
  public void handleEvent( Event arg0 ) {
   dialog.dispose();
  }
 } );
}

代码示例来源:origin: pentaho/pentaho-kettle

private void buildWidget() {
 wCheckBox = new Button( parentComposite, SWT.CHECK );
 wCheckBox.setText( buttonName );
 props.setLook( wCheckBox );
 FormData fdUseSSL = new FormData();
 fdUseSSL.top = new FormAttachment( parentComposite, 0 );
 fdUseSSL.left = new FormAttachment( 0, 0 );
 wCheckBox.setLayoutData( fdUseSSL );
 wCheckBox.addSelectionListener( new SelectionListener() {
 Label wlSSLProperties = new Label( parentComposite, SWT.LEFT );
 wlSSLProperties.setText( tableName );
 props.setLook( wlSSLProperties );
 FormData fdlSSLProperties = new FormData();
 fdlSSLProperties.top = new FormAttachment( wCheckBox, 10 );
 fdlSSLProperties.left = new FormAttachment( 0, 0 );
 wlSSLProperties.setLayoutData( fdlSSLProperties );

代码示例来源:origin: pentaho/pentaho-kettle

public Composite getComposite( Composite parent, ImportRuleInterface importRule ) {
 rule = (DatabaseConfigurationImportRule) importRule;
 databaseMeta = rule.getDatabaseMeta();
 PropsUI props = PropsUI.getInstance();
 composite = new Composite( parent, SWT.NONE );
 props.setLook( composite );
 composite.setLayout( new FillLayout() );
 label = new Label( composite, SWT.SINGLE | SWT.BORDER | SWT.LEFT );
 props.setLook( label );
 label.setText( "Database configuration : (not configured)" );
 button = new Button( composite, SWT.PUSH );
 button.setText( "Edit..." );
 button.addSelectionListener( new SelectionAdapter() {
  public void widgetSelected( SelectionEvent event ) {
   editDatabase();
  }
 } );
 return composite;
}

代码示例来源:origin: pentaho/pentaho-kettle

public void widgetSelected( SelectionEvent e ) {
  final Shell dialog = new Shell( shell, SWT.DIALOG_TRIM );
  dialog.setText( BaseMessages.getString( PKG, "JobGetPOP.SelectDate" ) );
  dialog.setImage( GUIResource.getInstance().getImageSpoon() );
  dialog.setLayout( new GridLayout( 3, false ) );
  final DateTime calendar = new DateTime( dialog, SWT.CALENDAR );
  final DateTime time = new DateTime( dialog, SWT.TIME | SWT.TIME );
  new Label( dialog, SWT.NONE );
  new Label( dialog, SWT.NONE );
  Button ok = new Button( dialog, SWT.PUSH );
  ok.setText( BaseMessages.getString( PKG, "System.Button.OK" ) );
  ok.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, false, false ) );
  ok.addSelectionListener( new SelectionAdapter() {
   public void widgetSelected( SelectionEvent e ) {
    Calendar cal = Calendar.getInstance();
    cal.set( Calendar.YEAR, calendar.getYear() );
    cal.set( Calendar.MONTH, calendar.getMonth() );
    cal.set( Calendar.DAY_OF_MONTH, calendar.getDay() );
    cal.set( Calendar.HOUR_OF_DAY, time.getHours() );
    cal.set( Calendar.MINUTE, time.getMinutes() );
    cal.set( Calendar.SECOND, time.getSeconds() );
    wReadFrom.setText( new SimpleDateFormat( JobEntryGetPOP.DATE_PATTERN ).format( cal.getTime() ) );
    dialog.close();
   }
  } );
  dialog.setDefaultButton( ok );
  dialog.pack();
  dialog.open();
 }
} );

代码示例来源:origin: pentaho/pentaho-kettle

shell.setImage( GUIResource.getInstance().getImageSpoon() );
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
wClose = new Button( shell, SWT.PUSH );
wClose.setText( BaseMessages.getString( PKG, "System.Button.Close" ) );
wClose.addListener( SWT.Selection, new Listener() {
 public void handleEvent( Event e ) {

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Setting the layout of an <i>Edit</i> option button. Either a button image is set - if existing - or a text.
 *
 * @param button
 *          The button
 */
private FormData layoutEditOptionButton( Button button ) {
 FormData fd = new FormData();
 Image editButton = GUIResource.getInstance().getEditOptionButton();
 if ( editButton != null ) {
  button.setImage( editButton );
  button.setBackground( GUIResource.getInstance().getColorWhite() );
  fd.width = editButton.getBounds().width + 20;
  fd.height = editButton.getBounds().height;
 } else {
  button.setText( BaseMessages.getString( PKG, "EnterOptionsDialog.Button.Edit" ) );
 }
 button.setToolTipText( BaseMessages.getString( PKG, "EnterOptionsDialog.Button.Edit.Tooltip" ) );
 return fd;
}

代码示例来源:origin: pentaho/pentaho-kettle

props.setLook( composite );
FormLayout compLayout = new FormLayout();
compLayout.marginHeight = Const.FORM_MARGIN;
compLayout.marginWidth = Const.FORM_MARGIN;
wlPassword = new Label( composite, SWT.RIGHT );
wlPassword.setText( BaseMessages.getString( PKG, "CreateDatabaseWizardPage2.Password.Label" ) );
props.setLook( wlPassword );
fdlPassword = new FormData();
wlPassword.setLayoutData( fdlPassword );
wPassword = new Text( composite, SWT.SINGLE | SWT.BORDER );
props.setLook( wPassword );
wTest = new Button( composite, SWT.PUSH );
wTest.setText( BaseMessages.getString( PKG, "CreateDatabaseWizardPage2.TestConnection.Button" ) );

代码示例来源:origin: caoxinyu/RedisClient

composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
Label lblNewLabel = new Label(composite, SWT.WRAP);
lblNewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
lblNewLabel.setText(RedisClient.i18nFile.getText(I18nFile.DONATIONMESSAGE));
Label label = new Label(composite, SWT.NONE);
label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
label.setAlignment(SWT.CENTER);
label.setImage(code);
composite_1.setLayout(new FillLayout(SWT.HORIZONTAL));
Button btnOk = new Button(composite_1, SWT.NONE);
btnOk.addSelectionListener(new SelectionAdapter() {
  @Override
btnOk.setText(RedisClient.i18nFile.getText(I18nFile.OK));

代码示例来源:origin: pentaho/pentaho-kettle

protected Button createSettingsButton( Composite p, String text, String title, Control top, SelectionAdapter sa ) {
 Button button = new Button( p, SWT.CHECK );
 button.setText( BaseMessages.getString( PKG, text ) );
 button.setToolTipText( BaseMessages.getString( PKG, title ) );
 props.setLook( button );
 FormData fd = new FormData();
 fd.left = new FormAttachment( 0, Const.MARGIN * 2 );
 if ( top == null ) {
  fd.top = new FormAttachment( 0, 10 );
 } else {
  fd.top = new FormAttachment( top, 5 );
 }
 fd.right = new FormAttachment( 100, 0 );
 button.setLayoutData( fd );
 button.addSelectionListener( sa );
 return button;
}

代码示例来源:origin: pentaho/pentaho-kettle

public void widgetSelected( SelectionEvent e ) {
  final Shell dialog = new Shell( shell, SWT.DIALOG_TRIM );
  dialog.setText( BaseMessages.getString( PKG, "MailInput.SelectDate" ) );
  dialog.setImage( GUIResource.getInstance().getImageSpoon() );
  dialog.setLayout( new GridLayout( 3, false ) );
  final DateTime calendar = new DateTime( dialog, SWT.CALENDAR );
  final DateTime time = new DateTime( dialog, SWT.TIME | SWT.TIME );
  new Label( dialog, SWT.NONE );
  new Label( dialog, SWT.NONE );
  Button ok = new Button( dialog, SWT.PUSH );
  ok.setText( BaseMessages.getString( PKG, "System.Button.OK" ) );
  ok.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, false, false ) );
  ok.addSelectionListener( new SelectionAdapter() {
   public void widgetSelected( SelectionEvent e ) {
    Calendar cal = Calendar.getInstance();
    cal.set( Calendar.YEAR, calendar.getYear() );
    cal.set( Calendar.MONTH, calendar.getMonth() );
    cal.set( Calendar.DAY_OF_MONTH, calendar.getDay() );
    cal.set( Calendar.HOUR_OF_DAY, time.getHours() );
    cal.set( Calendar.MINUTE, time.getMinutes() );
    cal.set( Calendar.SECOND, time.getSeconds() );
    wReadFrom.setText( new SimpleDateFormat( MailInputMeta.DATE_PATTERN ).format( cal.getTime() ) );
    dialog.close();
   }
  } );
  dialog.setDefaultButton( ok );
  dialog.pack();
  dialog.open();
 }
} );

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * build Ok Button.
 */
protected void buildOkButton() {
 Button ok = new Button( this.dialog, SWT.PUSH );
 ok.setText( BaseMessages.getString( PKG, "OlapInputDialog.About.Plugin.Close" ) );
 GridData grdData = new GridData( GridData.HORIZONTAL_ALIGN_CENTER );
 grdData.horizontalSpan = 2;
 grdData.verticalIndent = DEFAULT_INDENT;
 grdData.horizontalIndent = DEFAULT_INDENT;
 ok.setLayoutData( grdData );
 ok.addListener( SWT.Selection, new Listener() {
  public void handleEvent( Event arg0 ) {
   dialog.dispose();
  }
 } );
}

代码示例来源:origin: caoxinyu/RedisClient

protected void initContents() {
  Composite composite_1 = new Composite(shell, SWT.NONE);
  composite_1.setLayout(new FillLayout(SWT.HORIZONTAL));
  composite_1.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,
      false, 1, 1));
  btnOk = new Button(composite_1, SWT.NONE);
  btnOk.addSelectionListener(okSelection);
  btnOk.setText(RedisClient.i18nFile.getText(I18nFile.OK));
  Button btnCancel = new Button(composite_1, SWT.NONE);
  btnCancel.addSelectionListener(cancelSelection);
  btnCancel.setText(RedisClient.i18nFile.getText(I18nFile.CANCEL));
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Setting the layout of a <i>Reset</i> option button. Either a button image is set - if existing - or a text.
 *
 * @param button
 *          The button
 */
private FormData layoutResetOptionButton( Button button ) {
 FormData fd = new FormData();
 Image editButton = GUIResource.getInstance().getResetOptionButton();
 if ( editButton != null ) {
  button.setImage( editButton );
  button.setBackground( GUIResource.getInstance().getColorWhite() );
  fd.width = editButton.getBounds().width + 20;
  fd.height = editButton.getBounds().height;
 } else {
  button.setText( BaseMessages.getString( PKG, "EnterOptionsDialog.Button.Reset" ) );
 }
 button.setToolTipText( BaseMessages.getString( PKG, "EnterOptionsDialog.Button.Reset.Tooltip" ) );
 return fd;
}

代码示例来源:origin: pentaho/pentaho-kettle

protected void optionsSectionControls() {
 wClearLog = new Button( gDetails, SWT.CHECK );
 wClearLog.setText( BaseMessages.getString( PKG, "TransExecutionConfigurationDialog.ClearLog.Label" ) );
 wClearLog.setToolTipText( BaseMessages.getString( PKG, "TransExecutionConfigurationDialog.ClearLog.Tooltip" ) );
 props.setLook( wClearLog );
 FormData fdClearLog = new FormData();
 fdClearLog.top = new FormAttachment( 0, 10 );
 fdClearLog.left = new FormAttachment( 0, 10 );
 wClearLog.setLayoutData( fdClearLog );
 wSafeMode = new Button( gDetails, SWT.CHECK );
 wSafeMode.setText( BaseMessages.getString( PKG, "TransExecutionConfigurationDialog.SafeMode.Label" ) );
 FormData fdSafeMode = new FormData();
 fdSafeMode.top = new FormAttachment( wClearLog, 7 );
 wGatherMetrics = new Button( gDetails, SWT.CHECK );
 wGatherMetrics.setText( BaseMessages.getString( PKG, "TransExecutionConfigurationDialog.GatherMetrics.Label" ) );
 props.setLook( wGatherMetrics );
 FormData fdGatherMetrics = new FormData();
 wGatherMetrics.setLayoutData( fdGatherMetrics );
 wlLogLevel = new Label( gDetails, SWT.NONE );
 props.setLook( wlLogLevel );
 wlLogLevel.setText( BaseMessages.getString( PKG, "TransExecutionConfigurationDialog.LogLevel.Label" ) );
 wlLogLevel.setLayoutData( fdlLogLevel );

代码示例来源:origin: caoxinyu/RedisClient

composite.setLayout(new GridLayout(2, false));
btnExpire = new Button(composite, SWT.CHECK);
btnExpire.setText(RedisClient.i18nFile.getText(I18nFile.EXPIRE));
labelTTL = new Label(composite, SWT.NONE);
labelTTL.setEnabled(false);
labelTTL.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
labelTTL.setText(RedisClient.i18nFile.getText(I18nFile.TTLS));

代码示例来源:origin: pentaho/pentaho-kettle

private static Button newButton( final Composite parent ) {
 Button button = new Button( parent, SWT.PUSH );
 button.setImage( GUIResource.getInstance().getImageHelpWeb() );
 button.setText( BaseMessages.getString( PKG, "System.Button.Help" ) );
 button.setToolTipText( BaseMessages.getString( PKG, "System.Tooltip.Help" ) );
 FormData fdButton = new FormData();
 fdButton.left = new FormAttachment( 0, 0 );
 fdButton.bottom = new FormAttachment( 100, 0 );
 button.setLayoutData( fdButton );
 return button;
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public void widgetSelected( SelectionEvent e ) {
 final Shell dialog = new Shell( shell, SWT.DIALOG_TRIM );
 dialog.setText( BaseMessages.getString( PKG, "SalesforceInputDialog.SelectDate" ) );
 dialog.setImage( GUIResource.getInstance().getImageSpoon() );
 dialog.setLayout( new GridLayout( 3, false ) );
 new Label( dialog, SWT.NONE );
 new Label( dialog, SWT.NONE );
 Button ok = new Button( dialog, SWT.PUSH );
 ok.setText( BaseMessages.getString( PKG, "System.Button.OK" ) );
 ok.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, false, false ) );
 ok.addSelectionListener( new SelectionAdapter() {

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * build Ok Button.
 */
protected void buildOkButton() {
 Button ok = new Button( this.dialog, SWT.PUSH );
 ok.setText( BaseMessages.getString( PKG, "SapInputDialog.About.Plugin.Close" ) );
 GridData grdData = new GridData( GridData.HORIZONTAL_ALIGN_CENTER );
 grdData.horizontalSpan = 2;
 grdData.verticalIndent = DEFAULT_INDENT;
 grdData.horizontalIndent = DEFAULT_INDENT;
 ok.setLayoutData( grdData );
 ok.addListener( SWT.Selection, new Listener() {
  public void handleEvent( Event arg0 ) {
   dialog.dispose();
  }
 } );
}

相关文章

微信公众号

最新文章

更多

Button类方法