• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

changing txt value of a button in SWT

 
maroun Adolf
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I made an interface using SWT, it includes 14 buttons with text values respectively : Element_1, Element_2, ..., Element_14.

I want to write event handlers on each button stating that : when a button is clicked, the text "Element_1" showing in the button disappears, and the user enters the new text suppose : "new text".
after typing for example "new text" he clicks enter, and the button is now having the text "new text" instead of "Element_1"


Thanks guys
 
Arun Chidam
Ranch Hand
Posts: 79
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maroun Adolf wrote:Hi all,

I made an interface using SWT, it includes 14 buttons with text values respectively : Element_1, Element_2, ..., Element_14.

I want to write event handlers on each button stating that : when a button is clicked, the text "Element_1" showing in the button disappears, and the user enters the new text suppose : "new text".
after typing for example "new text" he clicks enter, and the button is now having the text "new text" instead of "Element_1"


Thanks guys


Hi Adolf,

You can do it as per below steps
1.register your button to selectionListener,
2.Add code in the WidgetSelected event to invoke a custom Input dialog.
3.In custom Input dialog create input text field(where user can input text)
4.Reset the button text field with the returned value from Custom Dialog(do remember to resize the button if text is bigger)

button.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
//text.setText("No worries!");
final InputDialog ip = new InputDialog(shell);//Custom Dialog
button.setText(ip.open());
}

 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
maroun Adolf
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Chidam,

it works, but of course you knew that

Thank you for your quick help


hi Ritchie,
I am glad to be here, still new to the Java environment, but hey, it is never too late to start learning

Regards,
Adolf
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic