This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes change the texts to a different one in a JButton each time it is pressed. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "change the texts to a different one in a JButton each time it is pressed." Watch "change the texts to a different one in a JButton each time it is pressed." New topic
Author

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

abrar alvi
Ranch Hand

Joined: Feb 01, 2012
Posts: 66

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

Joined: Jun 09, 2003
Posts: 4632
button.setText(button.getText().equals("click me")? "button clicked":"click me");
abrar alvi
Ranch Hand

Joined: Feb 01, 2012
Posts: 66

thank you
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

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


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: change the texts to a different one in a JButton each time it is pressed.
 
Similar Threads
programming style
Swing simple
need help with my code
Error !! in Swing
function scope?