Example usage for javax.swing.event ListSelectionEvent getFirstIndex

List of usage examples for javax.swing.event ListSelectionEvent getFirstIndex

Introduction

In this page you can find the example usage for javax.swing.event ListSelectionEvent getFirstIndex.

Prototype

public int getFirstIndex() 

Source Link

Document

Returns the index of the first row whose selection may have changed.

Usage

From source file:JListDemo.java

JListDemo(String s) {
    super(s);/*from  w  w  w . j a v  a2  s .com*/
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    ArrayList data = new ArrayList();
    data.add("Hi");
    data.add("Hello");
    data.add("Goodbye");
    data.add("Adieu");
    data.add("Adios");
    list = new JList(data.toArray());
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            if (evt.getValueIsAdjusting())
                return;
            System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex());
        }
    });
    cp.add(list, BorderLayout.CENTER);
}

From source file:ListIt.java

public ListIt() {
    JFrame f = new JFrame();
    final PartsListModel pcm = new PartsListModel();
    ListCellRenderer lcr = new MyLabelRenderer();
    JList jl = new JList(pcm);
    jl.setCellRenderer(lcr);/*from   w  w w .j ava 2  s .  com*/
    ListSelectionModel lsm = jl.getSelectionModel();
    lsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jl.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                String element[] = (String[]) pcm.getElementAt(e.getFirstIndex());
                System.out.println(element[0] + " : " + element[1] + " : " + element[2]);
            }
        }
    });
    JScrollPane jsp = new JScrollPane(jl);
    JComboBox jc = new JComboBox(pcm);
    jc.setRenderer(lcr);
    JButton jb = new JButton("Add Merchandise");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            pcm.addElement(partsList[(int) (Math.random() * partsList.length)]);
        }
    });
    Container c = f.getContentPane();
    c.add(jsp, BorderLayout.NORTH);
    c.add(jc, BorderLayout.CENTER);
    c.add(jb, BorderLayout.SOUTH);
    f.setSize(250, 250);
    f.show();
}

From source file:de.codesourcery.eve.skills.ui.components.ListEditingComponent.java

@SuppressWarnings("unchecked")
@Override//w  w  w.  ja  va2s .  c  o m
public void valueChanged(ListSelectionEvent event) {
    final T item = (T) model.getElementAt(event.getFirstIndex());
    selectionChanged(item);
}

From source file:feelings.analyser.views.MainView.java

public void init() {
    ExtractData data = new ExtractData();
    CleanData datatoClean = new CleanData();
    String[] textAnalyzer = new String[100];
    String textClean = "";
    String absolutUrl = System.getProperty("user.dir");
    File file = new File("Comentarios Mochila.txt");
    JOptionPane.showInputDialog(this, absolutUrl + "\\src\\assets\\Comentarios Mochila.txt");
    data.readFile(file);/*from w  ww .ja v  a 2s .  com*/
    AnalyzerText analyzertext = new AnalyzerText();
    for (String a : data.getPosts()) {
        datatoClean.setStreamToClean(a);
        datatoClean.textToLowerCase();
        textClean = datatoClean.removeAcentos();
        textClean = datatoClean.removePuntuationMarks(textClean);
        analyzertext.setPostToAnalyse(textClean);
        analyzertext.textAnalyze();
        dataAnalyzer = new ResultDataAnalyzer(a, analyzertext.getPositiveCount(),
                analyzertext.getNegativeCount());
        modelList.addElement(dataAnalyzer);
        System.out.println(textClean + "Buenas: " + analyzertext.getPositiveCount() + "Malas: "
                + analyzertext.getNegativeCount());

    }
    lstPosts.setModel(modelList);
    lstPosts.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            ResultDataAnalyzer o = new ResultDataAnalyzer();
            o = (ResultDataAnalyzer) lstPosts.getModel().getElementAt(e.getFirstIndex());
            auxPositive = o.getCountPositive();
            auxNegative = o.getCountNegative();
            dividendo = auxPositive + auxNegative;
            dataChart.setValue("Positivo", (auxPositive / dividendo) * 10);
            dataChart.setValue("Negativo", (auxNegative / dividendo) * 10);

        }

    });

}

From source file:com.mirth.connect.client.ui.SettingsPanelDatabaseTasks.java

@Override
public void valueChanged(ListSelectionEvent evt) {
    if (!evt.getValueIsAdjusting()) {
        int selectedRow = taskTable.getSelectedRow();
        boolean showRun = evt.getFirstIndex() > -1;
        boolean showCancel = false;

        if (showRun) {
            for (int row = 0; row < taskTable.getRowCount(); row++) {
                if (((DatabaseTask) taskTable.getValueAt(row, 1)).getStatus() == Status.RUNNING) {
                    showRun = false;//from www.  ja v  a2 s. co m
                    if (row == selectedRow) {
                        showCancel = true;
                    }
                }
            }
        }

        setVisibleTasks(2, 2, showRun);
        setVisibleTasks(3, 3, showCancel);

        Map<String, String> affectedChannels = new HashMap<String, String>();
        if (selectedRow > -1) {
            affectedChannels = ((DatabaseTask) taskTable.getValueAt(selectedRow, 1)).getAffectedChannels();
        }

        Object[][] data = new Object[affectedChannels.size()][2];
        int i = 0;

        for (String channelId : affectedChannels.keySet()) {
            data[i][0] = affectedChannels.get(channelId);
            data[i][1] = channelId;
            i++;
        }

        ((RefreshTableModel) channelsTable.getModel()).refreshDataVector(data);
    }
}

From source file:com.haskins.cloudtrailviewer.sidebar.EventsStats.java

private void addTable() {

    defaultTableModel.addColumn("");
    defaultTableModel.addColumn("Property");
    defaultTableModel.addColumn("Value");

    final LegendColourRenderer cellRenderer = new LegendColourRenderer();
    final JTable table = new JTable(defaultTableModel) {

        @Override/*from w  w  w.  ja v a  2 s .c  o  m*/
        public TableCellRenderer getCellRenderer(int row, int column) {
            if (column == 0) {
                return cellRenderer;
            }
            return super.getCellRenderer(row, column);
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        };
    };

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {

            if (e.getFirstIndex() >= 0) {

                String value = (String) defaultTableModel.getValueAt(table.getSelectedRow(), 1);
                eventTablePanel.setFilterString(value);
            }
        }
    });

    TableColumn column;
    for (int i = 0; i < 3; i++) {
        column = table.getColumnModel().getColumn(i);

        switch (i) {
        case 0:
            column.setMinWidth(15);
            column.setMaxWidth(15);
            column.setPreferredWidth(15);
            break;

        case 2:
            column.setMinWidth(70);
            column.setMaxWidth(70);
            column.setPreferredWidth(70);
            break;
        }
    }

    JScrollPane tablecrollPane = new JScrollPane(table);
    tablecrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

    this.add(tablecrollPane, BorderLayout.CENTER);
}

From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java

private Component createObsTable(ListSelectionModel seriesSelectionModel) {
    final XTable result = new XTable();
    ColorCellRenderer renderer = new ColorCellRenderer(FontAwesome.FA_CIRCLE_O);
    result.setDefaultRenderer(Color.class, renderer);
    result.setDefaultEditor(Color.class, new ColorCellEditor(colorSchemeSupport, renderer));
    result.setDefaultRenderer(Font.class, FontCellRenderer.INSTANCE);
    result.setDefaultEditor(Font.class, new FontCellEditor());
    result.setDefaultRenderer(Stroke.class, StrokeCellRenderer.INSTANCE);
    result.setDefaultEditor(Stroke.class, new StrokeCellEditor());
    seriesSelectionModel.addListSelectionListener(new ListSelectionListener() {
        @Override/*from   w ww  .  j  av a2 s.co m*/
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int index = e.getFirstIndex();
                result.setModel(index != -1 ? new ObsModel(support.seriesInfos[index].obsInfos) : null);
                result.getModel().addTableModelListener(new TableModelListener() {
                    @Override
                    public void tableChanged(TableModelEvent e) {
                        chart.fireChartChanged();
                    }
                });
            }
        }
    });
    return ModernUI.withEmptyBorders(new JScrollPane(result));
}

From source file:homenetapp.HomeNetAppGui.java

private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
    int index = evt.getFirstIndex();
    JList j = (JList) evt.getSource();
    homenet.Packet p = (homenet.Packet) j.getSelectedValue();

    //homenet.Packet p = (homenet.Packet)packetListModel.getElementAt(index);
    displayPacket(p);/*from   www.  ja  va2  s .  c om*/
}

From source file:org.clipsmonitor.gui.MapGeneratorTopComponent.java

private void PersonsListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_PersonsListValueChanged

    String[] persons = model.getListPerson();
    if (evt.getFirstIndex() != persons.length - 1) {
        String val = persons[evt.getFirstIndex()];
        String[] split = val.split("_");
        MakePersonList();/*from  www . ja v a2s  . co  m*/
        int pos = model.findIndexPosByColor(split[1]);
        MakeStepList(-1);
        MakeMoveList(pos, -1, "all");
        MakePathList(pos);
        setListEnable();
        setState(split[1]);
        updateLabel(state);
        actualPath = model.getLastPathOfPerson(state);
        if (!actualPath.equals("empty")) {
            String[][] move = model.getMoveCellMap(actualPath, -1);
            model.ApplyUpdateOnMoveMap(move);
        }

        model.CopyToActive(model.getMove());
        PreviewMap.repaint();
    } else {
        MakePersonList();
        MakeStepList(-1);
        MakeMoveList(-1, -1, "all");
        MakePathList(-1);
    }
}

From source file:org.clipsmonitor.gui.MapGeneratorTopComponent.java

private void StepListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_StepListValueChanged

    String value = (String) StepList.getModel().getElementAt(evt.getFirstIndex());
    String intSubStr = value.substring(5); // "Step " length
    int step = Integer.parseInt(intSubStr);
    MakeStepList(-1);//from   ww w .  j a  v  a2s .  c om
    MakePathList(-1);
    MakeMoveList(-1, step, "all");
    String[][] move = model.getMoveCellMap("none", step);
    model.ApplyUpdateOnMoveMap(move);
    model.CopyToActive(model.getMove());
    PreviewMap.repaint();
    setListEnable();
}