Skip to content

Instantly share code, notes, and snippets.

@figengungor
Last active December 14, 2015 19:39
Show Gist options
  • Select an option

  • Save figengungor/5137832 to your computer and use it in GitHub Desktop.

Select an option

Save figengungor/5137832 to your computer and use it in GitHub Desktop.
Java GUI >> Setting Background Color
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MyGUI extends JFrame {
JPanel jp1,jp2,jp3;
public MyGUI(){
setTitle("Background Color Example");
setSize(300,300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jp1.setBackground(Color.BLUE);
add(jp1);
jp2.setBackground(Color.RED);
add(jp2, BorderLayout.WEST);
jp3.setBackground(Color.GREEN);
add(jp3, BorderLayout.EAST);
}
public static void main(String [] args) {
new MyGUI();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment