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 AWT – Getting Data from Computer Clipboard

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

public class Main {

    public void displayTextFromClipboard() {

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Clipboard clipboard = toolkit.getSystemClipboard();
        Transferable tran = null;

        try {
            //The parameter to getContents is not currently used so null should
            //be sent. If the clipboard is currently not available (for example
            //it is used by another application) the method throws an
            //IllegalStateException.
            tran = clipboard.getContents(null);
        } catch (IllegalStateException ex) {
            System.out.println("The clipboard is unavailable.");
            return;
        }

        if (tran != null && tran.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            try {
                String clipboardContent = (String)tran.getTransferData(DataFlavor.stringFlavor);
                System.out.println(clipboardContent);
            } catch (UnsupportedFlavorException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        new Main().displayTextFromClipboard();
    }

}

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 3123