Results 1 to 6 of 6
  1. #1
    panic's Avatar
    panic is offline Member
    Join Date
    Mar 2009
    Posts
    12
    Rep Power
    0

    Default setIcon to jbutton

    hi,all!

    i am trying to add an icon to a button but the setIcon method doest work in my code, dont know,maybe i give the wrong directory,so i wait for your help :))

  2. #2
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    We can't just magically know what you are doing wrong.
    Maybe you could post the code which is relevant to help us understand what you are doing wrong.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Agree. Please post your code so we don't have to guess at what is wrong.

  4. #4
    panic's Avatar
    panic is offline Member
    Join Date
    Mar 2009
    Posts
    12
    Rep Power
    0

    Default

    so this is that part of my code in which i want every 8 buttons to be set icon:

    for (int i=0;i<sayac;i++){
    if (sira[i]==sira[sayac]) sayac--;
    }
    sayac++;

    if (sayac==9) devam=false;

    }while(devam);
    btn=new JButton[3][3];
    int k=0;

    for(int m=0;m<3;m++)
    for(int l=0;l<3;l++){
    int a=sira[k];

    if (a==0){
    bos_satir=m;
    bos_sutun=l;
    System.out.println (m);
    System.out.println (l);
    btn[m][l]=new JButton(str[a]);
    btn[m][l].setEnabled(false);
    btn[m][l].setVisible(false);
    btn[m][l].addActionListener(this);
    add(btn[m][l]);

    }else{
    Icon icon=new ImageIcon("Caucasus"+a+".jpg");
    btn[m][l]=new JButton();
    btn[m][l].setIcon(icon);
    //here i try to do that
    add(btn[m][l]);

    btn[m][l].addActionListener(this);
    }
    k++;
    }
    System.out.println (bos_satir);
    System.out.println (bos_sutun);
    hesapla(bos_satir,bos_sutun);
    }

    if you'll need thte whole code,i ll do that

  5. #5
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    Where are the image files at? Are they in the same directory as the jar file where your running java myProg ?

    Maybe you should try creating a full URL to the images so that you can be assured that it's getting the right place to look for the images.

  6. #6
    panic's Avatar
    panic is offline Member
    Join Date
    Mar 2009
    Posts
    12
    Rep Power
    0

    Default

    i wrote it in by netbeans,and the images are in resources directory of that project,but i also tried to write it

Similar Threads

  1. setIcon
    By pgag45 in forum New To Java
    Replies: 2
    Last Post: 05-15-2009, 07:12 AM
  2. JButton Problem
    By wassim in forum AWT / Swing
    Replies: 6
    Last Post: 02-18-2009, 10:29 PM
  3. Jbutton not working??
    By rmabrey in forum AWT / Swing
    Replies: 7
    Last Post: 09-24-2008, 05:30 PM
  4. Help with JButton
    By geoffreybarwise in forum New To Java
    Replies: 4
    Last Post: 05-21-2008, 10:48 AM
  5. Mouse over JButton
    By sandor in forum AWT / Swing
    Replies: 1
    Last Post: 05-17-2007, 09:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •