• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cant include picture in JButton

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wish to show a picture from this line instead of a yellow background !


if(plateau[j] == 0) terrainDeJeu.getComponent(i*7+j).setBackground(Color.yellow);

HOW DO I PROCEED?


public Container createContentPane()
{
plateau = new int[6][7];
for(int i=0; i<6; i++)
for(int j=0; j<7; j++)
{
plateau[j] = 0;
}
joueur = 1;
fin = false;

initComposants();

for ( int i=0 ; i<42 ; i++ )
{
JButton paneTmp = new JButton(iconJeu);
paneTmp.setEnabled(true);
paneTmp.setBackground(Color.orange);
terrainDeJeu.add(paneTmp);
}

return terrain;
}


private int plateau[][];
private JPanel terrainDeJeu;
private JPanel terrain;
 
Chitlesh GOORAH
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is the answer:
Component c = terrainDeJeu.getComponent(i*7+j).
JButton button = (JButton)c;
button.setIcon("myImage.jpg");
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Swing/AWT...
 
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic