Welcome to Dream.In.Code
Become a Java Expert!

Join 150,189 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,038 people online right now. Registration is fast and FREE... Join Now!




Image on a button

 
Reply to this topicStart new topic

Image on a button, cant get code to work help

RETNE
23 Sep, 2008 - 04:54 PM
Post #1

New D.I.C Head
*

Joined: 17 Nov, 2007
Posts: 22


My Contributions
i fond a code of the internet that allows u to put images on buttons, but i wasn't clearly explained and i cant get it to work mad.gif


CODE


                    ImageIcon ico = new ImageIcon("cow.jpeg");

                    p1.add(b1);
                    b1.addActionListener(this);
                    b1.setIcon(ico);
                    
                    this.add (p1);



any thig helps

User is offlineProfile CardPM
+Quote Post

pbl
RE: Image On A Button
23 Sep, 2008 - 05:09 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
ImageIcon ico = new ImageIcon("cow.jpeg");
b1 = new JButton(ico);
or
b1 = new JButton("Text", ico);

oups... looked at your post to fast
b1.setIcon(ico);
will also work is b1 has been created: b1 = new JButton();

This post has been edited by pbl: 23 Sep, 2008 - 05:48 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:13AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month