• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

changing txt value of a button in SWT

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 79
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}

 
Marshal
Posts: 80627
470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
maroun Adolf
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic