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("Animated_butterfly.gif"); label = new JLabel("A Butterfly", ic, JLabel.CENTER); label.setFont(new Font("Verdana", Font.BOLD, 18)); label.setBackground(Color.yellow); 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