Example usage for javax.swing DefaultListModel addElement

List of usage examples for javax.swing DefaultListModel addElement

Introduction

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

Prototype

public void addElement(E element) 

Source Link

Document

Adds the specified component to the end of this list.

Usage

From source file:se.cambio.cds.gdl.editor.view.panels.ListPanel.java

private void init() {
    this.setLayout(new BorderLayout());
    this.setBorder(BorderFactory.createTitledBorder(_title));
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
    JButton addButton = new JButton(GDLEditorImageUtil.ADD_ICON);
    addButton.setContentAreaFilled(false);
    addButton.setPreferredSize(new Dimension(16, 16));
    addButton.setBorderPainted(false);/* ww w  .  ja va2  s . c  o m*/
    addButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String value = JOptionPane.showInputDialog(EditorManager.getActiveEditorWindow(), _title, "");
            if (value != null) {
                DefaultListModel dlm = ((DefaultListModel) getJList().getModel());
                dlm.addElement(value);
                updateListModel(dlm);
            }
        }
    });
    JButton deleteButton = new JButton(GDLEditorImageUtil.DELETE_ICON);
    deleteButton.setContentAreaFilled(false);
    deleteButton.setPreferredSize(new Dimension(16, 16));
    deleteButton.setBorderPainted(false);
    deleteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int index = getJList().getSelectedIndex();
            if (index >= 0) {
                DefaultListModel dlm = ((DefaultListModel) getJList().getModel());
                dlm.removeElementAt(index);
                updateListModel(dlm);
            }
        }
    });
    buttonPanel.add(addButton);
    buttonPanel.add(deleteButton);
    this.add(buttonPanel, BorderLayout.WEST);
    this.add(getJList(), BorderLayout.CENTER);
}

From source file:se.trixon.jota.client.ui.editor.JobsPanel.java

private void init() {
    label.setText(Dict.JOBS.toString());

    addButton.setVisible(true);//from  w w  w  .ja  v  a  2s . c  om
    cloneButton.setVisible(true);
    editButton.setVisible(true);
    removeButton.setVisible(true);
    removeAllButton.setVisible(true);

    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    try {
        DefaultListModel model = new DefaultListModel();
        mManager.getServerCommander().getJobs().stream().forEach((job) -> {
            model.addElement(job);
        });
        setModel(model);
    } catch (RemoteException ex) {
        Logger.getLogger(JobsPanel.class.getName()).log(Level.SEVERE, null, ex);
    }
    list.setSelectedIndex(0);
}

From source file:se.trixon.jota.client.ui.editor.TasksPanel.java

private void init() {
    label.setText(Dict.TASKS.toString());

    addButton.setVisible(true);//www  .  java 2  s.c o  m
    cloneButton.setVisible(true);
    editButton.setVisible(true);
    removeButton.setVisible(true);
    removeAllButton.setVisible(true);

    try {
        DefaultListModel model = new DefaultListModel();
        mManager.getServerCommander().getTasks().stream().forEach((task) -> {
            model.addElement(task);
        });
        setModel(model);
    } catch (RemoteException ex) {
        Logger.getLogger(JobsPanel.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:se.trixon.solos.core.panel.FilePanel.java

@Override
public void onDirRefreshed(final Collection<File> files) {
    new Thread(new Runnable() {
        @Override/*from   w  w w.j  a  v a  2 s . com*/
        public void run() {
            DefaultListModel model = new DefaultListModel();
            for (File file : files) {
                model.addElement(file);
                Solos.log(file.getAbsolutePath());
            }
            mList.setModel(model);
        }
    }).start();
}

From source file:se.trixon.toolbox.rsync.job.JobManager.java

public DefaultListModel populateModel(DefaultListModel model) {
    model.clear();/*from   w  ww  .j a va2 s. com*/

    for (Job job : mJobs) {
        model.addElement(job);
    }

    return model;
}

From source file:se.trixon.toolbox.rsync.task.TaskManager.java

public DefaultListModel populateModel(DefaultListModel model) {
    model.clear();/*from   w  ww  .ja va  2s.  c  o m*/

    for (Task job : mTasks) {
        model.addElement(job);
    }

    return model;
}

From source file:unimelb.distributed_project.gui.JacardSimilarityMeasurePanel.java

/**
 * Load button's actionPerformed function to load the list of words to find nearest words
 * against all the words in the list loaded.
 *
 * @param e ActionEvent object//from   w  w w. j a v a2s .c  om
 */
private void loadListButtonActionPerformed(ActionEvent e) {

    JFileChooser jFileChooser = new JFileChooser();
    jFileChooser.setCurrentDirectory(new File("/home"));
    int result = jFileChooser.showOpenDialog(new JFrame());

    if (result == JFileChooser.APPROVE_OPTION) {
        File selectedFile = jFileChooser.getSelectedFile();
        listOfwordsFilePath = selectedFile.getPath();

        File f = new File(listOfwordsFilePath);

        try {
            if (f.exists()) {
                BufferedReader br = new BufferedReader(new FileReader(listOfwordsFilePath));
                String line;
                List<String> lines = new ArrayList<String>();
                DefaultListModel model = new DefaultListModel();
                while ((line = br.readLine()) != null) {
                    // process the line.
                    lines.add(line);
                    model.addElement(line);
                    log.debug(line);

                }

                wordList.setModel(model);
                wordList.updateUI();

            } else {
                log.debug("Creating file, wordOfList doesn't exist");

            }
        } catch (IOException e1) {
            log.debug("creating/loading file exception");
            e1.printStackTrace();
        }

        log.debug("Selected file: " + listOfwordsFilePath);
    } else {
        JOptionPane.showMessageDialog(this.mainFrame, "Please suggest where the listOfWords.txt text file is",
                "file is not selected", JOptionPane.ERROR_MESSAGE);

    }

}