package calendar; import java.awt.Color; import java.awt.GridLayout; import java.util.ArrayList; import java.util.Collections; import javax.swing.BoxLayout; import javax.swing.JPanel; import javax.swing.JScrollPane; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Adam Jama */ @SuppressWarnings("serial") public class AddressBookPanel extends JPanel{ private ArrayList<ContactPanel> m_contacts; private JPanel m_list; public AddressBookPanel() { m_contacts = new ArrayList<ContactPanel>(); m_list = new JPanel(); //m_list.setOpaque(false); m_list.setBackground(new Color(211, 189, 154)); for(int i = 0; i < Data.GetContacts().size(); i++) { ContactPanel cp = new ContactPanel(Data.GetContacts().get(i), this); //cp.setBackground(Color.red); cp.setOpaque(false); m_contacts.add(cp); } JScrollPane sp = new JScrollPane(m_list); sp.setOpaque(false); sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); //sp.setBackground(Color.red); this.setLayout(new GridLayout(1,1)); add(sp); AddEmpty(); } public void AddEmpty() { m_contacts.add(new ContactPanel(this)); render(); } void render() { Collections.sort(m_contacts); m_list.removeAll(); m_list.setLayout(new BoxLayout(m_list, BoxLayout.Y_AXIS)); for(int i = 0; i < m_contacts.size(); i++) { m_list.add(m_contacts.get(i)); } updateUI(); } }