Advertisement
VenomLust

Untitled

Jul 28th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.87 KB | None | 0 0
  1. Custom Cell :
  2. import java.awt.BorderLayout;
  3. import java.awt.Component;
  4. import java.awt.Dimension;
  5. import java.awt.Graphics;
  6. import java.awt.Image;
  7. import java.awt.image.BufferedImage;
  8.  
  9. import javax.swing.Box;
  10. import javax.swing.BoxLayout;
  11. import javax.swing.ImageIcon;
  12. import javax.swing.JLabel;
  13. import javax.swing.JList;
  14. import javax.swing.JPanel;
  15. import javax.swing.ListCellRenderer;
  16.  
  17. import com.nouty.classes.Contact_Info;
  18. import com.nouty.funcs.PhotoFuncs;
  19.  
  20. @SuppressWarnings("serial")
  21. public class CustomContactCellRender extends JPanel implements ListCellRenderer<Contact_Info>{
  22.    
  23.     JLabel name;
  24.     JLabel msg;
  25.     BufferedImage img;
  26.    
  27.     public CustomContactCellRender() {
  28.        
  29.         setOpaque(true);
  30.         setLayout(new BoxLayout(this , BoxLayout.Y_AXIS));
  31.        
  32.         JPanel overallPanel = new JPanel();
  33.         overallPanel.setLayout(new BoxLayout(overallPanel , BoxLayout.X_AXIS));
  34.         overallPanel.setPreferredSize(new Dimension(40,400));
  35.         add(overallPanel);
  36.        
  37.         JPanel firstPanel = new JPanel();
  38.         firstPanel.setPreferredSize(new Dimension(40,40));
  39.         firstPanel.setLayout(new BorderLayout());
  40.         overallPanel.add(firstPanel);
  41.        
  42.         JPanel statusPanel = new JPanel();
  43.         statusPanel.setPreferredSize(new Dimension(37,37));
  44.         statusPanel.setLayout(new BorderLayout());
  45.        
  46.         firstPanel.add(statusPanel , BorderLayout.CENTER);
  47.         firstPanel.add(Box.createRigidArea(new Dimension(3,40)) , BorderLayout.LINE_START);
  48.         firstPanel.add(Box.createRigidArea(new Dimension(3,40)) , BorderLayout.LINE_END);
  49.         firstPanel.add(Box.createRigidArea(new Dimension(40,3)) , BorderLayout.PAGE_END);
  50.         firstPanel.add(Box.createRigidArea(new Dimension(40,3)) , BorderLayout.PAGE_START);
  51.        
  52.         JPanel photoPanel = new JPanel(){
  53.             public void paintComponent(Graphics g) {
  54.                 g.drawImage(PhotoFuncs.photoResize(img, 32, 32), 0  , 0  ,null);
  55.             }
  56.         };
  57.         photoPanel.setPreferredSize(new Dimension(32,32));
  58.         photoPanel.setLayout(null);
  59.         statusPanel.add(photoPanel);
  60.        
  61.         JPanel secondPanel = new JPanel();
  62.         secondPanel.setLayout(new BoxLayout(secondPanel , BoxLayout.Y_AXIS));
  63.         overallPanel.add(secondPanel);
  64.        
  65.         secondPanel.add(Box.createRigidArea(new Dimension(3,this.getWidth())));
  66.        
  67.         name = new JLabel();
  68.         name.setPreferredSize(new Dimension(100,15));
  69.         secondPanel.add(name);
  70.        
  71.         secondPanel.add(Box.createRigidArea(new Dimension(4,this.getWidth())));
  72.        
  73.         msg = new JLabel();
  74.         msg.setPreferredSize(new Dimension(this.getWidth(),15));
  75.         secondPanel.add(msg);
  76.        
  77.         secondPanel.add(Box.createRigidArea(new Dimension(4,this.getWidth())));
  78.     };
  79.     @Override
  80.     public Component getListCellRendererComponent(JList list, Contact_Info value,
  81.             int index, boolean isSelected, boolean cellHasFocus) {
  82.        
  83.         img = value.getProfile_pic();
  84.         name.setText(value.getFirst_name() + " " + value.getLast_name() + " (" + value.getNickname() + ")");
  85.         msg.setText(value.getMsg());
  86.        
  87.         return this;
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement