Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Custom Cell :
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.image.BufferedImage;
- import javax.swing.Box;
- import javax.swing.BoxLayout;
- import javax.swing.ImageIcon;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JPanel;
- import javax.swing.ListCellRenderer;
- import com.nouty.classes.Contact_Info;
- import com.nouty.funcs.PhotoFuncs;
- @SuppressWarnings("serial")
- public class CustomContactCellRender extends JPanel implements ListCellRenderer<Contact_Info>{
- JLabel name;
- JLabel msg;
- BufferedImage img;
- public CustomContactCellRender() {
- setOpaque(true);
- setLayout(new BoxLayout(this , BoxLayout.Y_AXIS));
- JPanel overallPanel = new JPanel();
- overallPanel.setLayout(new BoxLayout(overallPanel , BoxLayout.X_AXIS));
- overallPanel.setPreferredSize(new Dimension(40,400));
- add(overallPanel);
- JPanel firstPanel = new JPanel();
- firstPanel.setPreferredSize(new Dimension(40,40));
- firstPanel.setLayout(new BorderLayout());
- overallPanel.add(firstPanel);
- JPanel statusPanel = new JPanel();
- statusPanel.setPreferredSize(new Dimension(37,37));
- statusPanel.setLayout(new BorderLayout());
- firstPanel.add(statusPanel , BorderLayout.CENTER);
- firstPanel.add(Box.createRigidArea(new Dimension(3,40)) , BorderLayout.LINE_START);
- firstPanel.add(Box.createRigidArea(new Dimension(3,40)) , BorderLayout.LINE_END);
- firstPanel.add(Box.createRigidArea(new Dimension(40,3)) , BorderLayout.PAGE_END);
- firstPanel.add(Box.createRigidArea(new Dimension(40,3)) , BorderLayout.PAGE_START);
- JPanel photoPanel = new JPanel(){
- public void paintComponent(Graphics g) {
- g.drawImage(PhotoFuncs.photoResize(img, 32, 32), 0 , 0 ,null);
- }
- };
- photoPanel.setPreferredSize(new Dimension(32,32));
- photoPanel.setLayout(null);
- statusPanel.add(photoPanel);
- JPanel secondPanel = new JPanel();
- secondPanel.setLayout(new BoxLayout(secondPanel , BoxLayout.Y_AXIS));
- overallPanel.add(secondPanel);
- secondPanel.add(Box.createRigidArea(new Dimension(3,this.getWidth())));
- name = new JLabel();
- name.setPreferredSize(new Dimension(100,15));
- secondPanel.add(name);
- secondPanel.add(Box.createRigidArea(new Dimension(4,this.getWidth())));
- msg = new JLabel();
- msg.setPreferredSize(new Dimension(this.getWidth(),15));
- secondPanel.add(msg);
- secondPanel.add(Box.createRigidArea(new Dimension(4,this.getWidth())));
- };
- @Override
- public Component getListCellRendererComponent(JList list, Contact_Info value,
- int index, boolean isSelected, boolean cellHasFocus) {
- img = value.getProfile_pic();
- name.setText(value.getFirst_name() + " " + value.getLast_name() + " (" + value.getNickname() + ")");
- msg.setText(value.getMsg());
- return this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement