Image on a button

cant get code to work help

Page 1 of 1

1 Replies - 626 Views - Last Post: 23 September 2008 - 06:09 PM Rate Topic: -----

#1 RETNE  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 17-November 07

Image on a button

Post icon  Posted 23 September 2008 - 05:54 PM

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 :angry:



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

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




any thig helps

Is This A Good Question/Topic? 0
  • +

Replies To: Image on a button

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Image on a button

Posted 23 September 2008 - 06:09 PM

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 September 2008 - 06:48 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1