PDA

Click to See Complete Forum and Search --> : How do I set the background of a jPanel?


Wynd
Feb 24th, 2001, 12:20 AM
Using somePanel.setBackground(); what goes in the parentheses? Thanks in advance anyone.

sail3005
Feb 24th, 2001, 01:20 AM
try importing java.awt.systemColor

sail3005
Feb 24th, 2001, 01:23 AM
from JDK documentation:

setBackground

public void setBackground(Color*c)

Sets the background color of this component.
Parameters:
c - The color to become this component's color. If this parameter is null then this component will inherit the
background color of its parent. background color.

Wynd
Feb 24th, 2001, 01:25 AM
I did, i imported java.awt.* and javax.swing.*

Feb 24th, 2001, 12:55 PM
I wonder if you were really having a "background" problem. Consider the following:

It is a JPanel, not a jPanel.
You may need to place this in a type of frame (Frame or JFrame).
Sun has guidelines as to mixing awt and swing.

//filename BG.java
import java.awt.Color; // or java.awt.*; but I only need the Color class
import javax.swing.*;

public class BG extends JFrame{
JPanel jp;
public BG(){
jp = new JPanel();
jp.setBackground(Color.black);//Preset black; Can also define custom color
getContentPane().add(jp);
setSize(100,100);
setVisible(true);
System.out.println("Finished Constructor");
}
public static void main(String[] args){
System.out.println("Running");
new BG();
System.out.println("Finished main. Hit Ctrl+C in dos shell to exit app.");
}
}

Wynd
Mar 12th, 2001, 07:09 PM
I got it, I wasn't putting "Color." in front of the color name.