aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes changing txt value of a button in SWT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "changing txt value of a button in SWT" Watch "changing txt value of a button in SWT" New topic
Author

changing txt value of a button in SWT

maroun Adolf
Greenhorn

Joined: Jun 23, 2011
Posts: 9
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

Joined: May 08, 2006
Posts: 79
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());
}


SCJP 1.4, SCWCD 1.4
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
. . . and welcome to the Ranch
maroun Adolf
Greenhorn

Joined: Jun 23, 2011
Posts: 9
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
 
subject: changing txt value of a button in SWT