簡體   English   中英

向SWT GUI添加幫助按鈕

[英]Adding help button to SWT GUI

我的Eclipse應用程序中有一個簡單的swt GUI,如下所示:

蝕應用窗口

它的實現非常簡單:

// creating the label
Label label = new Label(composite, SWT.NONE);
label.setText("Label");
// creating the input field
Text text = new Text(composite, SWT.BORDER);
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
text.setLayoutData(gridData);

我想在標簽和輸入元素之間添加一個按鈕,以便用戶可以獲得有關在字段中添加內容的其他幫助。

它可以是一個幫助按鈕,也可以是一個圖標,該圖標在鼠標懸停時顯示信息。

我該如何實施? 我將不勝感激任何幫助!

執行此操作的許多方法之一是使用信息字段修飾。

就像是:

Text text = new Text(composite, SWT.BORDER);

FieldDecorationRegistry decRegistry = FieldDecorationRegistry.getDefault();

FieldDecoration infoField = decRegistry.getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);

ControlDecoration decoration = new ControlDecoration(text, SWT.TOP | SWT.LEFT);
decoration.setImage(infoField.getImage());

decoration.setDescriptionText("Info decoration text");

GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);

// Space for decoration image
gridData.horizontalIndent = decRegistry.getMaximumDecorationWidth();

text.setLayoutData(gridData);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM