Posted By

willjosefi on 12/15/10


Tagged


Versions (?)

Outro teste ae


 / Published in: Java
 

  1. import java.awt.FlowLayout;
  2. import javax.swing.JFrame;
  3. import javax.swing.JLabel;
  4. import javax.swing.SwingConstants;
  5. import javax.swing.Icon;
  6. import javax.swing.ImageIcon;
  7.  
  8. public class LabelFrame extends JFrame {
  9. private JLabel label1;
  10. private JLabel label2;
  11. private JLabel label3;
  12.  
  13. public LabelFrame() {
  14. super("Teste de JLabel");
  15. setLayout(new FlowLayout()); // configura o layout da janela
  16.  
  17. label1 = new JLabel("Label 1");
  18. label1.setToolTipText("Este é o label 1");
  19. add(label1); //
  20.  
  21. ImageIcon bug = createImageIcon("somente.jpg", "algum texto qualquer");
  22. label2 = new JLabel("Label com texto e icone", bug, JLabel.LEFT);
  23. label2.setToolTipText("Este é o label 2");
  24. label2.setDisabledIcon(bug);
  25. label2.setEnabled(false);
  26. add(label2);
  27.  
  28. label3 = new JLabel();
  29. label3.setText("Label com icone em baixo");
  30. label3.setIcon(bug);
  31. label3.setHorizontalTextPosition(SwingConstants.CENTER);
  32. label3.setVerticalTextPosition(SwingConstants.BOTTOM);
  33. label3.setToolTipText("Este é o label 3");
  34. add(label3);
  35.  
  36. }
  37.  
  38. protected static ImageIcon createImageIcon(String path, String description) {
  39. java.net.URL imgURL = LabelFrame.class.getResource(path);
  40. if (imgURL != null) {
  41. return new ImageIcon(imgURL, description);
  42. } else {
  43. System.err.println("Couldn't find file: " + path);
  44. return null;
  45. }
  46. }
  47. }

Report this snippet  

You need to login to post a comment.