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 and the fly likes to change the button picture present in the resources folder in netbeans on click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "to change the button picture present in the resources folder in netbeans on click" Watch "to change the button picture present in the resources folder in netbeans on click" New topic
Author

to change the button picture present in the resources folder in netbeans on click

sanjay ramaswamy
Greenhorn

Joined: Feb 11, 2009
Posts: 29
Hey guys i have worked on 1 or 2 small assignments in swings . I am currently trying to develop a Burglar Alarm System . so i need to use buttons to start the system and shut it . so i have 2 .png image files in my resources folder in my netbeans project . so the button is default with the OFF.png file in it . so i want to perform an Action on the button . code goes like this


what am i trying to do ???
I am trying to change the icon of the button to ON on a button click and execute whatever the code when the system is supposed to be ON .vice versa for OFF .
please help me compare the resource files on the button .


"People who are unable to motivate themselves must be content with mediocrity , no matter how impressive their other talents " -Andrew Carnegie
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Why not use a simple boolean flag that indicates the state?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
sanjay ramaswamy
Greenhorn

Joined: Feb 11, 2009
Posts: 29
I am not able to get the state of the button . what is a state of the button??? I used the isSelected() method on button i.e


I am kinda starting to wonder...that i can get around by using 2 buttons i.e one for start and one for stop . I am developing a Home Security System. So i need to either manually start the system . so if press the start button it should display the stop icon on the button and execute the code seperately for stop etc .Hope ppl will come up with a code atleast guys...please
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Sanjay Jayaram Rao wrote:I am not able to get the state of the button . what is a state of the button??? I used the isSelected() method on button i.e

The isSelected method doesn't make much sense for normal JButtons. It's main use is in JToggleButton, JCheckButton and JRadioButton.

I am kinda starting to wonder...that i can get around by using 2 buttons i.e one for start and one for stop .

That could be an option. You simply hide (setVisible(false)) the one you don't want shown. However, seeing as the layout manager may give you problems, you can achieve the same with two Action instances instead:
The switching code is quite easy then:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: to change the button picture present in the resources folder in netbeans on click