/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package SwingDemo;

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author ta
 */
public class JLabelDemo extends JFrame {
    
   
   public JLabelDemo(String title) throws HeadlessException {
        
       this.setSize(600,800);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        
        this.setVisible(true);
        creatAndShow();
    }
    
    public static void main(String[] args) {
       new JLabelDemo("MY WINDOW");
        
        
    }

    private void creatAndShow() {
        
      JPanel jpn = new JPanel();
      jpn.setLayout(new GridLayout(1,3,5,5));
      
      //Chèn ảnh 
      Icon icon = new ImageIcon(getClass().getResource("java-heap-space-stack.jpg"));
      
      
      JLabel lb1 = new JLabel("label text only");
      JLabel lb2 = new JLabel(icon);
      JLabel lb3 = new JLabel("icon and text",icon,JLabel.CENTER);
      
      lb3.setVerticalTextPosition(JLabel.BOTTOM);
      lb3.setHorizontalTextPosition(JLabel.CENTER);
      
      jpn.add(lb1);
      jpn.add(lb2);
      jpn.add(lb3);
      Container con = getContentPane();
      con.add(jpn);
       pack();
        
    }

    
    
    
    
  
    
}
