Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

change the texts to a different one in a JButton each time it is pressed.

 
abrar alvi
Ranch Hand
Posts: 66
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends i am new to gui programming.. i was testing the following simple code

BUT, i want the button text to change back to its old text the second time i click it .

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
button.setText(button.getText().equals("click me")? "button clicked":"click me");
 
abrar alvi
Ranch Hand
Posts: 66
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.
In future, while posting code, please UseCodeTags. I have added them for you this time. As you can see the tags make the code much more easier to read and understand
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic