Example usage for javax.swing DefaultListModel DefaultListModel

List of usage examples for javax.swing DefaultListModel DefaultListModel

Introduction

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

Prototype

DefaultListModel

Source Link

Usage

From source file:joshua.ui.hypergraph_visualizer.HyperGraphViewer.java

public HyperGraphViewer(JungHyperGraph g, SymbolTable vocab) {
    super(new StaticLayout<Vertex, Edge>(g, new HyperGraphTransformer(g)));
    this.vocab = vocab;
    this.graph = g;
    this.edgeList = new JList(new DefaultListModel());
    this.edgeList.setCellRenderer(new HyperEdgeListCellRenderer(vocab));
    this.edgeList.addListSelectionListener(new HyperEdgeListSelectionListener(this));
    //      super(new DAGLayout<Vertex,Edge>(g));
    //      DelegateTree<Vertex,Edge> gtree = new DelegateTree<Vertex,Edge>(g);
    //      gtree.setRoot(g.getRoot());
    //      setGraphLayout(new TreeLayout<Vertex,Edge>(gtree));
    //      setGraphLayout(new StaticLayout<Vertex,Edge>(g, new HyperGraphTransformer(g)));
    getRenderContext().setVertexLabelTransformer(toStringTransformer());
    //      getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Vertex>());
    setVertexToolTipTransformer(toolTipTransformer());

    DefaultModalGraphMouse<Vertex, Edge> graphMouse = new DefaultModalGraphMouse<Vertex, Edge>();
    graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);
    this.setPickedVertexState(new HyperGraphPickedState(this));
    setGraphMouse(graphMouse);/*  www .ja v a  2 s .com*/
    addKeyListener(graphMouse.getModeKeyListener());

    getRenderContext().setVertexFillPaintTransformer(vertexPainter());
    //   getRenderContext().setEdgeStrokeTransformer(es);
    getRenderContext().setVertexShapeTransformer(ns);
    //   getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
}

From source file:com.palantir.ptoss.cinch.swing.JListWiringHarness.java

private static void updateListModel(JList list, List<?> newContents) {
    if (newContents == null) {
        newContents = ImmutableList.of();
    }//from   www  .j a v a  2 s .  com
    ListModel oldModel = list.getModel();
    List<Object> old = Lists.newArrayListWithExpectedSize(oldModel.getSize());
    for (int i = 0; i < oldModel.getSize(); i++) {
        old.add(oldModel.getElementAt(i));
    }
    if (old.equals(newContents)) {
        return;
    }
    Object[] selected = list.getSelectedValues();
    DefaultListModel listModel = new DefaultListModel();
    for (Object obj : newContents) {
        listModel.addElement(obj);
    }
    list.setModel(listModel);
    List<Integer> newIndices = Lists.newArrayListWithCapacity(selected.length);
    Set<Object> selectedSet = Sets.newHashSet(selected);
    for (int i = 0; i < listModel.size(); i++) {
        if (selectedSet.contains(listModel.elementAt(i))) {
            newIndices.add(i);
        }
    }
    list.setSelectedIndices(ArrayUtils.toPrimitive(newIndices.toArray(new Integer[0])));
}

From source file:events.ListDataEventDemo.java

public ListDataEventDemo() {
    super(new BorderLayout());

    //Create and populate the list model.
    listModel = new DefaultListModel();
    listModel.addElement("Whistler, Canada");
    listModel.addElement("Jackson Hole, Wyoming");
    listModel.addElement("Squaw Valley, California");
    listModel.addElement("Telluride, Colorado");
    listModel.addElement("Taos, New Mexico");
    listModel.addElement("Snowbird, Utah");
    listModel.addElement("Chamonix, France");
    listModel.addElement("Banff, Canada");
    listModel.addElement("Arapahoe Basin, Colorado");
    listModel.addElement("Kirkwood, California");
    listModel.addElement("Sun Valley, Idaho");
    listModel.addListDataListener(new MyListDataListener());

    //Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list.setSelectedIndex(0);//  w w  w .  j a va2 s  .  c  o m
    list.addListSelectionListener(this);
    JScrollPane listScrollPane = new JScrollPane(list);

    //Create the list-modifying buttons.
    addButton = new JButton(addString);
    addButton.setActionCommand(addString);
    addButton.addActionListener(new AddButtonListener());

    deleteButton = new JButton(deleteString);
    deleteButton.setActionCommand(deleteString);
    deleteButton.addActionListener(new DeleteButtonListener());

    ImageIcon icon = createImageIcon("Up16");
    if (icon != null) {
        upButton = new JButton(icon);
        upButton.setMargin(new Insets(0, 0, 0, 0));
    } else {
        upButton = new JButton("Move up");
    }
    upButton.setToolTipText("Move the currently selected list item higher.");
    upButton.setActionCommand(upString);
    upButton.addActionListener(new UpDownListener());

    icon = createImageIcon("Down16");
    if (icon != null) {
        downButton = new JButton(icon);
        downButton.setMargin(new Insets(0, 0, 0, 0));
    } else {
        downButton = new JButton("Move down");
    }
    downButton.setToolTipText("Move the currently selected list item lower.");
    downButton.setActionCommand(downString);
    downButton.addActionListener(new UpDownListener());

    JPanel upDownPanel = new JPanel(new GridLayout(2, 1));
    upDownPanel.add(upButton);
    upDownPanel.add(downButton);

    //Create the text field for entering new names.
    nameField = new JTextField(15);
    nameField.addActionListener(new AddButtonListener());
    String name = listModel.getElementAt(list.getSelectedIndex()).toString();
    nameField.setText(name);

    //Create a control panel, using the default FlowLayout.
    JPanel buttonPane = new JPanel();
    buttonPane.add(nameField);
    buttonPane.add(addButton);
    buttonPane.add(deleteButton);
    buttonPane.add(upDownPanel);

    //Create the log for reporting list data events.
    log = new JTextArea(10, 20);
    JScrollPane logScrollPane = new JScrollPane(log);

    //Create a split pane for the log and the list.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, listScrollPane, logScrollPane);
    splitPane.setResizeWeight(0.5);

    //Put everything together.
    add(buttonPane, BorderLayout.PAGE_START);
    add(splitPane, BorderLayout.CENTER);
}

From source file:ExtendedDnDDemo.java

private JPanel createList() {
    DefaultListModel listModel = new DefaultListModel();
    listModel.addElement("List 0");
    listModel.addElement("List 1");
    listModel.addElement("List 2");
    listModel.addElement("List 3");
    listModel.addElement("List 4");
    listModel.addElement("List 5");
    listModel.addElement("List 6");
    listModel.addElement("List 7");
    listModel.addElement("List 8");

    JList list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    JScrollPane scrollPane = new JScrollPane(list);
    scrollPane.setPreferredSize(new Dimension(400, 100));

    list.setDragEnabled(true);/*from w  w  w . j a v  a  2s  .c o m*/
    list.setTransferHandler(new ListTransferHandler());

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createTitledBorder("List"));
    return panel;
}

From source file:gtu._work.ui.StringArrayMakerUI.java

private void initGUI() {
    try {//from   w  w w. j av a 2s.  c o m
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel1.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(525, 267));
                    {
                        ListModel jList1Model = new DefaultListModel();
                        jList1 = new JList();

                        jScrollPane2.setViewportView(jList1);
                        jList1.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(jList1).defaultJListKeyPressed(evt);
                            }
                        });
                        jList1.setModel(jList1Model);
                    }
                }
                {
                    jButton1 = new JButton();
                    jPanel1.add(jButton1, BorderLayout.NORTH);
                    jButton1.setText("\u8cbc\u4e0a");
                    jButton1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jButton1ActionPerformed(evt);
                        }
                    });
                }
                {
                    jPanel3 = new JPanel();
                    FlowLayout jPanel3Layout = new FlowLayout();
                    jPanel3Layout.setAlignment(FlowLayout.RIGHT);
                    jPanel1.add(jPanel3, BorderLayout.WEST);
                    jPanel3.setLayout(jPanel3Layout);
                    jPanel3.setPreferredSize(new java.awt.Dimension(50, 291));
                    {
                        jCheckBox1 = new JCheckBox();
                        jPanel3.add(jCheckBox1);
                        jCheckBox1.setText("\\n");
                    }
                    {
                        jCheckBox2 = new JCheckBox();
                        jPanel3.add(jCheckBox2);
                        jCheckBox2.setText("\\t");
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("jPanel2", null, jPanel2, null);
                {
                    jButton2 = new JButton();
                    jPanel2.add(jButton2, BorderLayout.NORTH);
                    jButton2.setText("\u7522\u751f");
                    jButton2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jButton2ActionPerformed(evt);
                        }
                    });
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(525, 291));
                    {
                        jTextArea1 = new JTextArea();
                        jScrollPane1.setViewportView(jTextArea1);
                        jTextArea1.setText("");
                    }
                }
            }
        }
        pack();
        this.setSize(546, 382);
    } catch (Exception e) {
        // add your error handling code here
        e.printStackTrace();
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchRankFrame.java

@Override
public void actionPerformed(ActionEvent e) {
    RankTableTab activeTab = getActiveTab();
    if (e.getActionCommand() != null && activeTab != null) {
        if (e.getActionCommand().equals("Find")) {
            BufferedImage back = ImageUtils.createCompatibleBufferedImage(3, 3, BufferedImage.TRANSLUCENT);
            Graphics g = back.getGraphics();
            g.setColor(new Color(120, 120, 120, 120));
            g.fillRect(0, 0, back.getWidth(), back.getHeight());
            g.setColor(new Color(120, 120, 120));
            g.drawLine(0, 0, 3, 3);/*  w w w  .  j a v a2  s. c om*/
            g.dispose();
            TexturePaint paint = new TexturePaint(back,
                    new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));
            jxSearchPane.setBackgroundPainter(new MattePainter(paint));
            DefaultListModel model = new DefaultListModel();

            for (int i = 0; i < activeTab.getRankTable().getColumnCount(); i++) {
                TableColumnExt col = activeTab.getRankTable().getColumnExt(i);
                if (col.isVisible()) {
                    if (col.getTitle().equals("Name") || col.getTitle().equals("Tag")
                            || col.getTitle().equals("Stamm")) {
                        model.addElement(col.getTitle());
                    }

                }
            }
            jXColumnList.setModel(model);
            jXColumnList.setSelectedIndex(0);
            jxSearchPane.setVisible(true);
        }
    }

}

From source file:com.iisigroup.ris.WebFileScanUtilBrowserUI.java

private void initGUI() {
    final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);
    try {//  w  w w . j ava  2  s.  c o  m
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("browser source code");
        {
            informationMenu = new JPopupMenu();
            setComponentPopupMenu(this, informationMenu);
        }
        {
            ListModel openFileListModel = new DefaultListModel();
            openFileList = new JList();
            openFileList.setModel(openFileListModel);
            getContentPane().add(openFileList, BorderLayout.NORTH);
            openFileList.setPreferredSize(new java.awt.Dimension(663, 281));
            openFileList.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent evt) {
                    swingUtil.invokeAction("openFileList.valueChanged", evt);
                }
            });
            openFileList.addMouseMotionListener(new MouseMotionAdapter() {
                public void mouseMoved(MouseEvent evt) {
                    swingUtil.invokeAction("openFileList.mouseMoved", evt);
                }
            });
            openFileList.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent evt) {
                    swingUtil.invokeAction("openFileList.keyPressed", evt);
                }
            });
        }
        {
            jPanel1 = new JPanel();
            GroupLayout jPanel1Layout = new GroupLayout((JComponent) jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            getContentPane().add(jPanel1, BorderLayout.SOUTH);
            jPanel1.setPreferredSize(new java.awt.Dimension(478, 35));
            {
                openSelected = new JButton();
                openSelected.setText("open all");
                openSelected.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("openSelected.actionPerformed", evt);
                    }
                });
            }
            jPanel1Layout.setHorizontalGroup(jPanel1Layout.createSequentialGroup().addContainerGap(178, 178)
                    .addComponent(openSelected, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(174, Short.MAX_VALUE));
            jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup().addGap(7)
                    .addComponent(openSelected, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 6, Short.MAX_VALUE));
        }
        {
            informationMenu = new JPopupMenu();
        }

        this.setSize(486, 350);
        this.setLocationRelativeTo(null);

        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        // ?tooltip
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        int initialDelay = ToolTipManager.sharedInstance().getInitialDelay();
        ToolTipManager.sharedInstance().setInitialDelay(0);
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        // ?tooltip
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        swingUtil.addAction("openFileList.mouseClicked", new Action() {
            public void action(EventObject evt) throws Exception {
                DefaultListModel model = (DefaultListModel) openFileList.getModel();
                int pos = openFileList.getLeadSelectionIndex();
                if (pos == -1) {
                    return;
                }
                setOpenFileListToolTip();
                MouseEvent eeev = (MouseEvent) evt;
                if (eeev.getClickCount() != 2) {
                    return;
                }
                MFile file = (MFile) model.elementAt(pos);
                openSource(file.file);
            }
        });
        final JListUtil jlistUtil = JListUtil.newInstance(openFileList);
        swingUtil.addAction("openFileList.keyPressed", new Action() {
            public void action(EventObject evt) throws Exception {
                jlistUtil.defaultJListKeyPressed((KeyEvent) evt);
                setOpenFileListToolTip();
            }
        });
        swingUtil.addAction("openSelected.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                DefaultListModel model = (DefaultListModel) openFileList.getModel();
                for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) {
                    MFile file = (MFile) enu.nextElement();
                    openSource(file.file);
                }
            }
        });
        swingUtil.addAction("openFileList.mouseMoved", new Action() {
            public void action(EventObject evt) throws Exception {
                setOpenFileListToolTip();
            }
        });
        swingUtil.addAction("openFileList.valueChanged", new Action() {
            public void action(EventObject evt) throws Exception {
                System.out.println(evt);
                setOpenFileListToolTip();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ListCutPaste.java

public ListCutPaste() {
    super(new BorderLayout());
    lh = new ListTransferHandler();

    JPanel panel = new JPanel(new GridLayout(1, 3));
    DefaultListModel list1Model = new DefaultListModel();
    list1Model.addElement("alpha");
    list1Model.addElement("beta");
    list1Model.addElement("gamma");
    list1Model.addElement("delta");
    list1Model.addElement("epsilon");
    list1Model.addElement("zeta");
    JList list1 = new JList(list1Model);
    list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane sp1 = new JScrollPane(list1);
    sp1.setPreferredSize(new Dimension(400, 100));
    list1.setDragEnabled(true);//  ww  w. j a  v a2s  .  c o  m
    list1.setTransferHandler(lh);
    list1.setDropMode(DropMode.ON_OR_INSERT);
    setMappings(list1);
    JPanel pan1 = new JPanel(new BorderLayout());
    pan1.add(sp1, BorderLayout.CENTER);
    pan1.setBorder(BorderFactory.createTitledBorder("Greek Alphabet"));
    panel.add(pan1);

    DefaultListModel list2Model = new DefaultListModel();
    list2Model.addElement("uma");
    list2Model.addElement("dois");
    list2Model.addElement("tres");
    list2Model.addElement("quatro");
    list2Model.addElement("cinco");
    list2Model.addElement("seis");
    JList list2 = new JList(list2Model);
    list2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list2.setDragEnabled(true);
    JScrollPane sp2 = new JScrollPane(list2);
    sp2.setPreferredSize(new Dimension(400, 100));
    list2.setTransferHandler(lh);
    list2.setDropMode(DropMode.INSERT);
    setMappings(list2);
    JPanel pan2 = new JPanel(new BorderLayout());
    pan2.add(sp2, BorderLayout.CENTER);
    pan2.setBorder(BorderFactory.createTitledBorder("Portuguese Numbers"));
    panel.add(pan2);

    DefaultListModel list3Model = new DefaultListModel();
    list3Model.addElement("adeen");
    list3Model.addElement("dva");
    list3Model.addElement("tri");
    list3Model.addElement("chyetirye");
    list3Model.addElement("pyat");
    list3Model.addElement("shest");
    JList list3 = new JList(list3Model);
    list3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list3.setDragEnabled(true);
    JScrollPane sp3 = new JScrollPane(list3);
    sp3.setPreferredSize(new Dimension(400, 100));
    list3.setTransferHandler(lh);
    list3.setDropMode(DropMode.ON);
    setMappings(list3);
    JPanel pan3 = new JPanel(new BorderLayout());
    pan3.add(sp3, BorderLayout.CENTER);
    pan3.setBorder(BorderFactory.createTitledBorder("Russian Numbers"));
    panel.add(pan3);

    setPreferredSize(new Dimension(500, 200));
    add(panel, BorderLayout.CENTER);
}

From source file:uk.co.petertribble.jangle.SnmpTreePanel.java

/**
 * Create a new SnmpTreePanel, starting exploration at the specified OID.
 *
 * @param startOID the OID to start from
 *///from  w ww.  j a v a  2  s .  c  o  m
public SnmpTreePanel(String startOID) {
    this.startOID = startOID;
    setLayout(new BorderLayout());

    jtpl = new JTabbedPane();
    model = new DefaultListModel();
    oidList = new ArrayList<SnmpObject>();
    slist = new JList(model);
    slist.addListSelectionListener(this);
    slist.setCellRenderer(new SnmpListCellRenderer());
    jtpl.add(SnmpResources.getString("SNMP.LIST.TEXT"), new JScrollPane(slist));

    // we use explicit placement so the tabs can be manipulated later
    jtpr = new JTabbedPane();

    // details tab
    jp1 = new JPanel(new BorderLayout());
    jp2 = new JPanel(new BorderLayout());
    tp = new JingleTextPane("text/plain");
    jp1.add(new JScrollPane(tp));
    // jp2 holds the chart
    jp2 = new JPanel(new BorderLayout());
    JSplitPane jpt = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jp1, jp2);
    jpt.setOneTouchExpandable(true);
    jpt.setDividerLocation(120);

    jtpr.insertTab(SnmpResources.getString("SNMP.DETAILS.TEXT"), (Icon) null, jpt, (String) null, TAB_D);

    tpdesc = new JingleTextPane("text/plain");
    jtpr.insertTab(SnmpResources.getString("SNMP.ABOUT.TEXT"), (Icon) null, new JScrollPane(tpdesc),
            (String) null, TAB_A);

    // siblings tab
    tpsiblings = new JingleTextPane("text/plain");
    jp3 = new JPanel(new BorderLayout());
    jp3t = new JPanel(new BorderLayout());
    JSplitPane jps = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jp3t, jp3);
    jps.setOneTouchExpandable(true);
    jps.setDividerLocation(200);
    jtpr.insertTab(SnmpResources.getString("SNMP.SIBLINGS.TEXT"), (Icon) null, jps, (String) null, TAB_S);

    // cousins tab
    tpcousins = new JingleTextPane("text/plain");
    jp4 = new JPanel(new BorderLayout());
    jp4t = new JPanel(new BorderLayout());
    JSplitPane jpc = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jp4t, jp4);
    jpc.setOneTouchExpandable(true);
    jpc.setDividerLocation(200);
    jtpr.insertTab(SnmpResources.getString("SNMP.COUSINS.TEXT"), (Icon) null, jpc, (String) null, TAB_C);

    // split pane to hold the lot
    JSplitPane psplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jtpl, jtpr);
    psplit.setOneTouchExpandable(true);
    psplit.setDividerLocation(200);
    add(psplit);
}

From source file:captureplugin.drivers.defaultdriver.AdditionalParams.java

private void fillModel(DeviceConfig config) {
    Vector<Object> vec = new Vector<Object>(config.getParamList());
    mListModel = new DefaultListModel();

    for (Object aVec : vec) {
        mListModel.addElement(aVec);/*  ww  w  .  ja  va  2  s .  co m*/
    }

    if (vec.size() == 0) {
        mListModel.addElement(new ParamEntry());
    }

}