So like the title says, I'm trying to set the background color of a panel within a frame so that they'd both have different colors. What I tried so far is using the setBackground
method on each alone or at the same time and the result I got is always only one color showing, which is weird because the inner frame shouldn't be able to change the outer frame's settings, right?
code example:
public class frameStuff{
private JFrame frame;
private frame1 in_frame;
@SuppressWarnings("serial")
class frame1 extends JPanel {
frame1(){
super();
}
public void paint(Graphics g){
}
}
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frameStuff window = new frameStuff();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public frameStuff() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 500, 350);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
// frame.getContentPane().setBackground(Color.GRAY);/*if this line wasn't a comment then everything would be grey instead of white as it's now.
in_frame = new frame1();
in_frame.setBounds(100, 100, 350, 220);
in_frame.setBackground(Color.BLUE);
in_frame.setVisible(true);//this doesn't seem to matter whatever the case
frame.getContentPane().add(in_frame);
}
}