Advertisement
raisul82

Swing JLabelImage

Mar 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1.  
  2. import java.awt.Color;
  3. import java.awt.Container;
  4. import javax.swing.ImageIcon;
  5. import javax.swing.JFrame;
  6. import javax.swing.JLabel;
  7.  
  8.  
  9. public class JLabelImage extends JFrame {
  10.  
  11. private ImageIcon img;
  12. private JLabel imgLabel;
  13. private Container c;
  14.  
  15.  
  16. JLabelImage()
  17. {
  18. setVisible(true);
  19. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20. setBounds(100,50,800,600);
  21. setTitle("Image Page");
  22.  
  23. iconMethod();
  24. }
  25.  
  26. public void iconMethod()
  27. {
  28. c=this.getContentPane();
  29. c.setLayout(null);
  30. c.setBackground(Color.RED);
  31. img=new ImageIcon(getClass().getResource("html.png"));
  32. this.setIconImage(img.getImage());
  33. imgLabel=new JLabel(img);
  34. c.add(imgLabel);
  35. imgLabel.setBounds(100,20,img.getIconWidth(),img.getIconHeight());
  36. //imgLabel.setBounds(1000,30,150,200);
  37. //c.add(imgLabel);
  38.  
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement