import java.awt.*; import java.awt.event.*; import javax .swing.*; public class LabelDemo{ private JFrame frame; private JLabel label; public LabelDemo(){ frame=new JFrame("a simple swing app"); Toolkit tk=frame.getToolkit(); Dimension dim=tk.getScreenSize(); int width=(int)dim.getWidth(); int height=(int)dim.getHeight(); frame.setSize(width,height); frame.setLayout(new FlowLayout()); ImageIcon ic= new ImageIcon("giphy.gif"); label=new JLabel("A Shining planet",ic,JLabel.CENTER); label.setFont(new Font("Verdana",Font.BOLD,18)); label.setBackground(Color.blue); frame.add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public static void main(String[] args){ new LabelDemo(); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter