File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT / JFace 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
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply 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
Greenhorn

Joined: Feb 01, 2012
Posts: 7

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
Rancher

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

Joined: Feb 01, 2012
Posts: 7

thank you
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 7602

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


[Donate a pint, save a life!] [How to ask questions]
 
 
subject: change the texts to a different one in a JButton each time it is pressed.
 
Threads others viewed
Error !! in Swing
need help with my code
programming style
function scope?
Swing simple
IntelliJ Java IDE