• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cant include picture in JButton

 
Chitlesh GOORAH
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
There is the answer:
Component c = terrainDeJeu.getComponent(i*7+j).
JButton button = (JButton)c;
button.setIcon("myImage.jpg");
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing/AWT...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!