tags:

views:

539

answers:

4

how to set a background color for the jframe ???

+2  A: 

Retrieve the content pane for the frame and use the setBackground() method inherited from Component to change the color.

Example:

myJFrame.getContentPane().setBackground( desiredColor );
Brandon E Taylor
A: 

You can use a container like so:

Container c = JFrame.getContentPane();
c.setBackground(Color.red);

You must of course import java.awt.Color for the red color constant.

John T
A: 

To set the background color for JFrame:

getContentPane().setBackground(Color.YELLOW);  //Whatever color
iwanttoprogram
A: 

That's another method:

private void RenkMouseClicked(java.awt.event.MouseEvent evt) {
   renk=JColorChooser.showDialog(null,"Arka plan rengini buradan seçiniz",renk);
   Container a=this.getContentPane();
   a.setBackground(renk);
}

I'm using netbeans ide. So JFrame.getContentPane() didn't run. I used JFrame.getContentPane()'s class equivalent this.getContentPane method.

Abdullah