Java Swing – Remove JFrame Title Bar

import javax.swing.JFrame;

public class RemoveJFrameTitleBar {

    public static void main(String[]args) {

        //Create a JFrame
        JFrame frame = new JFrame();

        //Method setUndecorated(true) will eliminate JFrame title bar
        frame.setUndecorated(true);

        //Set JFrame size to :
        //Width : 400 pixels
        //Height : 400 pixels
        frame.setSize(400,400);

        //Make JFrame visible. So we can see it.
        frame.setVisible(true);
    }

}

Java Swing – Set JFrame Background Image

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.FlowLayout;

public class PutImageOnJFrame extends JPanel {

    public PutImageOnJFrame() {
        setOpaque(false);
        setLayout(new FlowLayout());
    }

    public static void main(String[]args) {
        JFrame myFrame = new JFrame("Put Image");
        JButton button1 = new JButton("Sample 1");
        JButton button2 = new JButton("Sample 2");

        PutImageOnJFrame c = new PutImageOnJFrame();
        c.add(button1);
        c.add(button2);

        myFrame.add(c);
        myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        myFrame.setSize(400,400);
        myFrame.setVisible(true);
    }

    public void paint(Graphics g) {
        //IT DEPEND ON YOUR PICTURE AND PUT IT'S LOCATION IN
        Image a=Toolkit.getDefaultToolkit().getImage("E:\\_JAVA_\\---SOURCE CODE---\\bg.jpg");
        g.drawImage(a,0,0,getSize().width,getSize().height,this);
        super.paint(g);
    }

}

Java Swing – Set JPanel Background Color

import javax.swing.JPanel;
import javax.swing.JFrame;

import java.awt.Color;

public class SetJPanelBackgroundColor {

	public static void main(String[]args) {

		//Create panel using JPanel
		JPanel panel = new JPanel();

		//Create JFrame with title (Set JPanel background color)
		JFrame frame = new JFrame("Set JPanel background color");

		//Set color base on RGB
		//You can get RGB value for your color at "Color picker" at above
		//R=255
		//G=0
		//B=0
		Color color = new Color(255,0,0);

		//Set JPanel background color to color that you choose
		panel.setBackground(color);

		//Add JPanel into JFrame
		frame.add(panel);

		//Set default close operation for JFrame
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		//Set JFrame size
		frame.setSize(500,300);

		//Make JFrame visible
		frame.setVisible(true);
	}

}

Page 1 of 212