Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package swingExercises;
  2.  
  3. import java.awt.GridLayout;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JLabel;
  7. import javax.swing.SwingConstants;
  8.  
  9. import javax.imageio.ImageIO;
  10.  
  11. public class GridLabels2 {
  12.  
  13.     public static void main(String[] args) {
  14.        
  15.         JFrame jfrm = new JFrame("Show labels");
  16.         jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  17.        
  18.         jfrm.setLayout(new GridLayout(3, 1));
  19.         jfrm.setSize(700, 500);
  20.        
  21.         JLabel[][] labels = new JLabel[3][1];
  22.        
  23.         labels[0][0] = new JLabel("Label Tester");
  24.         labels[1][0] = new JLabel(ImageIO.read(new File("C:\\Users\\AJB\\Downloads\\logoDataDino.gif")));
  25.         labels[2][0] = new JLabel(ImageIO.read(new File("C:\\Users\\AJB\\Downloads\\logoSquirrelSQL.gif")) + "text and icon");
  26.        
  27.         jfrm.getContentPane().add(labels[0][0]);
  28.         jfrm.getContentPane().add(labels[1][0]);
  29.         jfrm.getContentPane().add(labels[2][0]);
  30.        
  31.         labels[0][0].setHorizontalAlignment(SwingConstants.CENTER);
  32.        
  33.         jfrm.setVisible(true);
  34.        
  35.     }
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement