Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java J2EE
private JPanel addToolbar() {    
 
		JPanel jp1=new JPanel();
		jp1.setLayout(new FlowLayout());  
 
		JButton jb7=new JButton("exit ");
		jb7.addActionListener(this);
		jb7.setForeground(new Color(00,00,255));	
		jp1.add(jb7);
here how to set the image near to the button field this is button create code but how can i set image on the button field
Posted 3-Apr-13 21:46pm
Edited 11-May-13 23:49pm
v5
Comments
Filipe Marques at 4-Apr-13 4:32am
   
Hi, look at this, I hope that helps you: http://stackoverflow.com/questions/3775373/java-how-to-add-image-to-jlabel
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

By reading your question I think that you want to add an image on your button. You could try something like this:
import javax.imageio.ImageIO; //needed
import java.io.File;
 
    public void initialize(){
 
        //create your jframe
        //add you panel to it
        //add your button, set the actionListeners etc.
        File imageFile=new File("yourImage.png");
        Image image=ImageIO.read(imageFile);
 
        yourButton.setIcon(new ImageIcon(image));
 

    }
 
This should do the trick.
Best regards.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Have an image tag and a button in your form and on the onclick event of the button, write something as below:
 
protected void button_click()
{
ImageID.ImageUrl="Images/pic.jpg";
}
 
It should do the trick.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  JButton button = new JButton();
  try {
    Image iconImg = ImageIO.read(getClass().getResource("resources/test.bmp"));
    button.setIcon(new ImageIcon(iconImg));
  } catch (IOException ex) {
  }
Here, image file is assumed to be inside src/resources folder.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 436
1 Maciej Los 249
2 BillWoodruff 199
3 /\jmot 180
4 Suraj Sahoo | Coding Passion 170
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 14 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100