setBackground(Color.cyan) does not work

J

Jenny

Hi,

How should I use setBackground(Color.cyan)? It does not change the color.

import javax.swing.*;
import java.awt.*;
public class Windows {
public static void main(String[] args) {
JFrame f = new JFrame("hello");
f.setSize(200, 300);
f.setLocation(100, 100);
f.setForeground(Color.pink);
f.setVisible(true);

JWindow w = new JWindow();
w.setSize(200, 300);
w.setLocation(400, 100);
w.setBackground(Color.cyan);
w.setVisible(true);
}}


Thank you
 
R

Roedy Green

import javax.swing.*;
import java.awt.*;
public class Windows {
public static void main(String[] args) {
JFrame f = new JFrame("hello");
f.setSize(200, 300);
f.setLocation(100, 100);
f.setForeground(Color.pink);
f.setVisible(true);

JWindow w = new JWindow();
w.setSize(200, 300);
w.setLocation(400, 100);
w.setBackground(Color.cyan);
w.setVisible(true);
}}

see
http://mindprod.com/jgloss/contentpane.html

Here is what you should have written:

import java.awt.Color;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JWindow;

public class NoBackground
{
public static void main(String[] args)
{
JFrame f = new JFrame("hello");
Container fc = f.getContentPane();
f.setSize(200, 300);
f.setLocation(100, 100);
fc.setBackground(Color.green);
fc.setForeground(Color.pink);
f.setVisible(true);

JWindow w = new JWindow();
Container wc = w.getContentPane();
w.setSize(200, 300);
w.setLocation(400, 100);
wc.setBackground(Color.cyan);
w.setVisible(true);
}
}
 
Joined
May 9, 2014
Messages
1
Reaction score
0
Hi,

How should I use setBackground(Color.cyan)? It does not change the color.

import javax.swing.*;
import java.awt.*;
public class Windows {
public static void main(String[] args) {
JFrame f = new JFrame("hello");
f.setSize(200, 300);
f.setLocation(100, 100);
f.setForeground(Color.pink);
f.setVisible(true);

JWindow w = new JWindow();
w.setSize(200, 300);
w.setLocation(400, 100);
w.setBackground(Color.cyan);
w.setVisible(true);
}}


Thank you

Just put in the color name with ALL CAPS:yell: Remember it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top