Example usage for javax.swing JList repaint

List of usage examples for javax.swing JList repaint

Introduction

In this page you can find the example usage for javax.swing JList repaint.

Prototype

public void repaint(Rectangle r) 

Source Link

Document

Adds the specified region to the dirty region list if the component is showing.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList list = new JList(new CheckListItem[] { new CheckListItem("apple"), new CheckListItem("orange"),
            new CheckListItem("mango"), new CheckListItem("mango"), new CheckListItem("mango"),
            new CheckListItem("mango"), new CheckListItem("mango"), new CheckListItem("mango"),
            new CheckListItem("mango"), new CheckListItem("mango"), new CheckListItem("mango"),

            new CheckListItem("paw paw"), new CheckListItem("banana") });
    list.setCellRenderer(new CheckListRenderer());
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addMouseListener(new MouseAdapter() {
        @Override//from  w  w  w  . j  a  v  a2s  .c  o  m
        public void mouseClicked(MouseEvent event) {
            JList list = (JList) event.getSource();
            int index = list.locationToIndex(event.getPoint());// Get index of item
                                                               // clicked
            CheckListItem item = (CheckListItem) list.getModel().getElementAt(index);
            item.setSelected(!item.isSelected()); // Toggle selected state
            list.repaint(list.getCellBounds(index, index));// Repaint cell
        }
    });
    frame.getContentPane().add(new JScrollPane(list));
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

static ImageIcon makeImageIcon(URL url, JComboBox combo, int row) {
    ImageIcon icon = new ImageIcon(url);
    icon.setImageObserver(new ImageObserver() {
        public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
            if (combo.isShowing() && (infoflags & (FRAMEBITS | ALLBITS)) != 0) {
                if (combo.getSelectedIndex() == row) {
                    combo.repaint();// w w  w  . j  a v  a  2s .c  o m
                }
                BasicComboPopup p = (BasicComboPopup) combo.getAccessibleContext().getAccessibleChild(0);
                JList list = p.getList();
                if (list.isShowing()) {
                    list.repaint(list.getCellBounds(row, row));
                }
            }
            return (infoflags & (ALLBITS | ABORT)) == 0;
        };
    });
    return icon;
}