How to add icons on a button or any component in java

Ads
 

How to add icons on a button or any component in java

View Answers

October 14, 2008 at 4:16 PM

Hi,


import javax.swing.*;
import java.awt.*;

public class IconButtonDemo{
public static void main(String[] args){
JFrame frame = new JFrame("Icon on button");
JButton button = new JButton("Roseindia.net");
Icon imgicon = new ImageIcon("icon_confused.gif");
JPanel panel = new JPanel();
button.setIcon(imgicon);
panel.add(button);
frame.add(panel, BorderLayout.NORTH);
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

------------------------------------------

Visit for more information.

http://www.roseindia.net/java/example/java/swing/

Thanks.

Ads









Related Tutorials/Questions & Answers:
how to add components (like button , checkbox etc) in a table column in core java
how to add components (like button , checkbox etc) in a table column in core java  plz tell me how to add components(like button, checkbox, radiobutton etc)in a table column in core java
how to add a update button in the following jsp
how to add a update button in the following jsp  Once the excel from the following jsp is loaded to the broswer, how to add a button in the jsp to allow the user to update the excel? thanks, <%@page import="java.io.*"%>
Advertisements
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
How to add BigDecimal in Java?
How to add BigDecimal in Java?  Hi, I have two BigDecimal variables. I want to add these two values. How to add BigDecimal in Java? Thanks   Hello, I will show you how you can add two BigDecimal? Suppose you have
How to add a columns with a button set to a Jtable built with database result set
How to add a columns with a button set to a Jtable built with database result..., there should be another button to get further details of a account such as transactions... that button column to the table which is built with database result set. i would thank
How to call java method on Button click in jsp?
How to call java method on Button click in jsp?  How to call java method on Button click in jsp
how to add database in Java Applet
how to add database in Java Applet  hi every java master or Java Professional my name is vincent i'm java beginners hope u all can ,tech me how to add database in Java Applet below this code is my applet source code . thank
How to find java jobs at any where in india
How to find java jobs at any where in india   Hi, I want information about java related jobs in india.where can i find that details
How to add radio button value in a table for particular field?
How to add radio button value in a table for particular field?  Hi,I... dynamically from other table and two radio button one for present and the second... one radio button for text field then it insert only one value absent OR present
How to add dynamic table in java
How to add dynamic table in java  How to add dynamic table in java   import java.awt.*; import java.sql.*; import java.util.*; import javax.swing.*; import java.awt.event.*; import javax.swing.table.*; public class
How to Hide Button using Java Swing
How to Hide Button using Java Swing  Hi, I just begin to learn java programming. How to hide the button in Java programming. Please anyone suggest... Programming application how to hide the buttons using Java Swing. Please Visit
How to add key value pair in Java
How to add key value pair in Java  Hi, I have to store the key and value pair in Java. How to store key value pair in Java? Thanks   Hi, You can use the put method of Hashtable. Check the tutorial Creating a Hash
How to add
How to add   Hi, I want to make a website which will recommend users... to be viewed after clicking a link/button/whatever mentioning -"Next 10 recommendations". Please tell me what code should I use. Or is there any workaround
how to add date and change date in java - netbeans
how to add date and change date in java - netbeans  I need to code use to increase date How to get date after 30 days using netbeans
How to add two numbers in Java?
How to add two numbers in a Java program? In Java you can easily add two number by using the plus (+) operator. The plus operator will add two... how to sum(add) two numbers in Java. Check more tutorials at: Java
uinavigationcontroller add right button
uinavigationcontroller add right button  Hi, How to add the right button programatically to a UINavigation Controller? Thanks   Hi, You can use the following code: - (void)viewDidLoad { [super viewDidLoad
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers  how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
dynamicly add component to jsf page.
dynamicly add component to jsf page.  i want display image or text from database on jsf page. so i want to add components dynamicly. how am i do this. thanks for answers...   Please visit the following link: http
struts2 how can we add an radio button to form using a class(doa)
struts2 how can we add an radio button to form using a class(doa)  Hi I had created an class of subscription,and iam trying to add an radio button on the registration form how to do plz help me out here is my code model
struts2 how can we add an radio button to form using a class(doa)
struts2 how can we add an radio button to form using a class(doa)  Hi I had created an class of subscription,and iam trying to add an radio button on the registration form how to do plz help me out here is my code model
How to add a file in GZIP file format in Java programme.
How to add a file in GZIP file format in Java programme.  Hi please help me. How to add a file GZIP File format in Java program. If example..., This is the example and suggest link that will help you related to how to add the file
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???  How can change Button Label value Every Time when... Button1 = " any Alphabet "... ....is this Possible through Probability
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???  How can change Button Label value Every Time when... Button1 = " any Alphabet "... ....is this Possible through Probability
How can you add elements of two arrayLists in java?
How can you add elements of two arrayLists in java?  if you have an arrayList of tempArr = [hi, my, name, is, john] and another arrayList..., is d, john e] how do you go about
how to use button in array
how to use button in array  plz tell me how to code for button in array
how can add new line character into ajax response for java
how can add new line character into ajax response for java   i want to populated brand drop-down list and state drop-down list by changing on country... down will be in a new line how can i do this i m showing my codes here please
how can add new line character into ajax response for java
how can add new line character into ajax response for java   i want to populated brand drop-down list and state drop-down list by changing on country... down will be in a new line how can i do this i m showing my codes here please
How would you create a button with rounded edges?
rectangle around any component and set the button?s border...How would you create a button with rounded edges?   How would you create a button with rounded edges?   Hi, Here is the answer, We can
how to open a web page using proxy in java and handling button event in that web page..?
how to open a web page using proxy in java and handling button event... and then clicking "confirm" button. this process is repeated for 3 to 5 times...can use any... and opens a web page i.e for example and then clicks a "yes" button in that page
How to get Button Id ?
How to get Button Id ?  How to get Button ID instead of its value in Servlet. (I am not using jsp right now
Write an applet program to transfer the content of the text field into the component on clicking a button
Write an applet program to transfer the content of the text field into the component on clicking a button  Write an applet program to transfer the content of the text field into the component on clicking a button

Ads