The following code fragment which can be used within main method or in constructor of the class tells you how to change the look and feel of a java program (java application). This sample code sets the LookAndFeel of the java application into Windows Look and Feel.
Tutorials, tips and tricks about java programming language. Answers for many doubts about java programming language. Answering many howtos. Sample java projects and source code, java games, java programs for java practical labs.
Search This Blog
Showing posts with label change. Show all posts
Showing posts with label change. Show all posts
How to Change Image in JButton in Java - Set Icon of JButton
In this post we are discussing how to change the image in button in Java. There may be situations in
programming where we want to know how to set JButton image in java or to change button icon in java. The java code to change the icon of a Jbutton is so short. We use the
method in JButton class. The setIcon method takes an ImageIcon object as an argument. I will show you a sample java code in which the icon of button is set. First of all, you have to copy the icon image (jpg, bmp, png or gif image) to the src folder in the project directory. You may also place it in some folder inside the src folder. If you are using netbeans IDE, you can simply drag and drop the image file into the desired folder in the projects pane. After copying the icon image to src folder (or any subfolder in it), use the following code to set it as the button's icon.
Jbutton with Image set |
setIcon()
playbtn.setIcon(new ImageIcon(getClass().getResource("/manhaj/images/play.png"))); |
Subscribe to:
Posts (Atom)