Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to do Dialog return a String?
How to do Dialog return a String? [message #448069] Thu, 30 December 2004 10:23 Go to next message
Eclipse UserFriend
Originally posted by: dicesCAVA.ctonet.it

I must a Dialog with Text field who return text in field if click ok.
How i can do that?
I wrote:

public class Question extends MessageDialog {

public Question(Shell parentShell, String dialogTitle,Image
dialogTitleImage, String dialogMessage, int dialogImageType,String[]
dialogButtonLabels, int defaultIndex,String text) {
super(parentShell, dialogTitle, dialogTitleImage, dialogMessage,
dialogImageType, dialogButtonLabels, defaultIndex);
this.mess=text;
// TODO Auto-generated constructor stub
}

private Text text=null;
private String mess=null;

public static String show(Shell parent, String title,String message){
Question q=new Question(parent, title, null,message, QUESTION, new
String[]{IDialogConstants.YES_LABEL,IDialogConstants.NO_LABE L}, 0,"");
if(q.open()==0)
return q.text.getText();
return "";
}

protected Control createMessageArea(Composite composite) {

text = new Text(composite, SWT.SINGLE);
text.setText(mess);
GridData data=new GridData(
GridData.HORIZONTAL_ALIGN_CENTER
| GridData.VERTICAL_ALIGN_BEGINNING);
data.widthHint =
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSA GE_AREA_WIDTH);
text.setLayoutData(data);
return super.createMessageArea(composite);
}
}

but is wrong, help me.
(Sorry for my spaghetti English)
Re: How to do Dialog return a String? [message #448087 is a reply to message #448069] Thu, 30 December 2004 23:24 Go to previous message
Daniel Spiewak is currently offline Daniel SpiewakFriend
Messages: 263
Registered: July 2009
Senior Member
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="serif">Use the following form:<br>
<br>
public class MyDialog extends Dialog {<br>
&nbsp;&nbsp;&nbsp; private Shell shell;<br>
<br>
&nbsp;&nbsp;&nbsp; public MyDialog(Shell parent) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; shell = new Shell(parent, SWT.DIALOG_TRIM);<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; public String open() {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; shell.open();<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; // etc<br>
&nbsp;&nbsp;&nbsp; }<br>
}<br>
</font><br>
SaThot wrote:
<blockquote cite="midopsjtgh8mv5horlisaDjehwty@djehwty.mes" type="cite">I
must a Dialog with Text field who return text in field if click ok.
<br>
How i can do that?
<br>
I wrote:
<br>
<br>
public class Question extends MessageDialog {
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;public Question(Shell parentShell, String dialogTitle,Image&nbsp;
dialogTitleImage, String dialogMessage, int dialogImageType,String[]&nbsp;
dialogButtonLabels, int defaultIndex,String text) {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; super(parentShell, dialogTitle, dialogTitleImage,
dialogMessage,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dialogImageType, dialogButtonLabels, defaultIndex);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; this.mess=text;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; // TODO Auto-generated constructor stub
<br>
&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
&nbsp;&nbsp;&nbsp;&nbsp;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;private Text text=null;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;private String mess=null;
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;public static String show(Shell parent, String title,String
message){
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Question q=new Question(parent, title, null,message, QUESTION,
new&nbsp; String[]{IDialogConstants.YES_LABEL,IDialogConstants.NO_LABE L},
0,"");
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if(q.open()==0)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return q.text.getText();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return "";
<br>
&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;protected Control createMessageArea(Composite composite) {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; text = new Text(composite, SWT.SINGLE);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; text.setText(mess);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; GridData data=new GridData(
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GridData.HORIZONTAL_ALIGN_CENTER
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | GridData.VERTICAL_ALIGN_BEGINNING);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; data.widthHint =&nbsp;
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSA GE_AREA_WIDTH);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; text.setLayoutData(data);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return super.createMessageArea(composite);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
}
<br>
<br>
but is wrong, help me.
<br>
(Sorry for my spaghetti English)
<br>
</blockquote>
</body>
</html>
Previous Topic:Icon and Title in standalone Help System
Next Topic:Gradients in CTabFolder
Goto Forum:
  


Current Time: Fri Apr 19 05:38:00 GMT 2024

Powered by FUDForum. Page generated in 0.02511 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top