cardlistpanel.java

来自「java绘图 java awt 经典绘图的例子,对于初学awt模块的人非常有帮助」· Java 代码 · 共 55 行

JAVA
55
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package cardmanager;import java.awt.BorderLayout;import javax.swing.BorderFactory;import javax.swing.DefaultListModel;import javax.swing.JFrame;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.ListSelectionModel;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;/** * * @author zhaolin */public class CardListPanel extends JPanel{    private JList list;    private DefaultListModel model;    public CardListPanel(){        initConponent();    }    private void initConponent() {        this.setLayout(new BorderLayout());        this.setBorder(BorderFactory.createTitledBorder("名片列表"));        list = new JList();        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        list.setModel(CardManagerModel.getInstance().getListModel());        list.addListSelectionListener(new ListSelectionListener(){            public void valueChanged(ListSelectionEvent e) {                Card selectedCard = (Card)list.getSelectedValue();                CardManagerModel.getInstance().setCurrentCard(selectedCard);                CardManagerFrame cmf = (CardManagerFrame)getTopLevelAncestor();                cmf.fireCardChanged();            }        });        this.add(new JScrollPane(list));    }        public static void main(String[] args) {        JFrame f = new JFrame();        f.setContentPane(new CardListPanel());        f.pack();        f.setVisible(true);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?