• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

changing txt value of a button in SWT

 
Greenhorn
Posts: 9
  • 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
 
Ranch Hand
Posts: 79
  • Likes 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());
}

 
Marshal
Posts: 65113
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
maroun Adolf
Greenhorn
Posts: 9
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!