Java 复制和粘贴消息对话框消息
我正在创建一个带有一些信息的MessageDialogJava 复制和粘贴消息对话框消息,java,eclipse,eclipse-plugin,Java,Eclipse,Eclipse Plugin,我正在创建一个带有一些信息的MessageDialog MessageDialog.openInformation(getShell(), "Success", "Change "+getNumber()+" has been created."); 我希望能够复制对话框中的数字,以便我可以粘贴到其他地方。有没有办法设置MessageDialog以便我可以完成此操作 可以找到API。我在API中没有找到任何真正帮助我的东西。否,MessageDialog使用标签来显示消息。为了允许C&P,您需
MessageDialog.openInformation(getShell(), "Success", "Change "+getNumber()+" has been created.");
我希望能够复制对话框中的数字,以便我可以粘贴到其他地方。有没有办法设置MessageDialog以便我可以完成此操作
可以找到API。我在API中没有找到任何真正帮助我的东西。否,MessageDialog使用
标签来显示消息。为了允许C&P,您需要一个Text
小部件。因此,您必须创建自己的org.eclipse.jface.dialogs.Dialog
子类
您可以查看InputDialog
的源代码作为示例。要使文本小部件只读,请使用SWT.read_only
style标志创建它。只需使用JTextArea即可
然后
JTextArea tA= new JTextArea("your message.");
tA.setEditable(true);
然后您可以添加
MessageDialog.openInformation(getShell(), "Success", "Change "+getNumber()+" has been created.");
之后,通过稍微更改它(创建JTextArea,然后将其作为消息传递给JOptionPane)。您可以创建一个派生自MessageDialog
的类,并使用如下内容覆盖createMessageArea
方法:
public class MessageDialogWithCopy extends MessageDialog
{
public MessageDialogWithCopy(Shell parentShell, String dialogTitle, Image dialogTitleImage,
String dialogMessage, int dialogImageType, String [] dialogButtonLabels, int defaultIndex)
{
super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType,
dialogButtonLabels, defaultIndex);
}
@Override
protected Control createMessageArea(final Composite composite)
{
Image image = getImage();
if (image != null)
{
imageLabel = new Label(composite, SWT.NULL);
image.setBackground(imageLabel.getBackground());
imageLabel.setImage(image);
imageLabel.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false));
}
// Use Text control for message to allow copy
if (message != null)
{
Text msg = new Text(composite, SWT.READ_ONLY | SWT.MULTI);
msg.setText(message);
GridData data = new GridData(SWT.FILL, SWT.TOP, true, false);
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
msg.setLayoutData(data);
}
return composite;
}
public static void openInformation(Shell parent, String title, String message)
{
MessageDialogWithCopy dialog
= new MessageDialogWithCopy(parent, title, null, message, INFORMATION,
new String[] {IDialogConstants.OK_LABEL}, 0);
dialog.open();
}
}
真倒霉我会调查的。谢谢这个问题是用eclipse标记的,所以它是关于SWT的,而不是关于Swing的。我有点搞不清楚这应该如何工作。我没有要传递到方法中的组合。我想我可以创造一个。然后我会使用组合打开信息吗?您创建一个从MessageDialog派生的类,并在该类中重写createMessageArea
方法。添加了更多的类