Example usage for javax.swing DefaultListModel copyInto

List of usage examples for javax.swing DefaultListModel copyInto

Introduction

In this page you can find the example usage for javax.swing DefaultListModel copyInto.

Prototype

public void copyInto(Object[] anArray) 

Source Link

Document

Copies the components of this list into the specified array.

Usage

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultListModel model = new DefaultListModel();
    model.ensureCapacity(1000);/*  w  w  w . j a  v  a  2 s .  c om*/
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 5; j++) {
            model.addElement(labels[j]);
        }
    }
    Object[] objs = new Object[10];

    model.copyInto(objs);

    JList jlist2 = new JList(model);
    jlist2.setVisibleRowCount(4);
    jlist2.setFixedCellHeight(12);
    jlist2.setFixedCellWidth(200);
    JScrollPane scrollPane2 = new JScrollPane(jlist2);
    frame.add(scrollPane2, BorderLayout.CENTER);

    frame.setSize(300, 350);
    frame.setVisible(true);
}

From source file:de.pavloff.spark4knime.jsnippet.ui.JarListPanel.java

/**
 * Get the jar files defined in this panel.
 * @return the jar files// www . j  ava2s . c o m
 */
public String[] getJarFiles() {
    DefaultListModel<String> jarListModel = (DefaultListModel<String>) m_addJarList.getModel();
    String[] copy = new String[jarListModel.getSize()];
    if (jarListModel.getSize() > 0) {
        jarListModel.copyInto(copy);
    }
    return copy;
}

From source file:org.shaman.rpg.editor.dialog.DialogVisualElement.java

private void updatePersons() {
    if (isInsideSetupVisuals) {
        return;/*from w ww .  j a v a2s.c om*/
    }
    //Extract persons
    @SuppressWarnings("unchecked")
    final DefaultListModel<String> listModel = (DefaultListModel<String>) personsList.getModel();
    final String[] newPersons = new String[listModel.size()];
    listModel.copyInto(newPersons);
    LOG.info("settings persons to " + Arrays.toString(newPersons));
    final String[] oldPersons = dialog.getPersonList();

    //send to dialog
    dialog.setPersonList(newPersons);
    updateDialogPersons();

    // undo/redo
    undoRedo.undoableEditHappened(new UndoableEditEvent(dialog, new AbstractUndoableEdit() {

        @Override
        public void undo() throws CannotUndoException {
            super.undo();
            isInsideSetupVisuals = true;
            listModel.clear();
            listModel.ensureCapacity(oldPersons.length);
            for (String s : oldPersons) {
                listModel.addElement(s);
            }
            LOG.info("settings persons to " + Arrays.toString(oldPersons));
            dialog.setPersonList(oldPersons);
            updateDialogPersons();
            isInsideSetupVisuals = false;
        }

        @Override
        public void redo() throws CannotRedoException {
            super.redo();
            isInsideSetupVisuals = true;
            listModel.clear();
            listModel.ensureCapacity(newPersons.length);
            for (String s : newPersons) {
                listModel.addElement(s);
            }
            LOG.info("settings persons to " + Arrays.toString(newPersons));
            dialog.setPersonList(newPersons);
            updateDialogPersons();
            isInsideSetupVisuals = false;
        }

    }));
}