Example usage for javax.swing.event ListSelectionEvent getSource

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

Introduction

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

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:SelectionHandler.java

public void valueChanged(ListSelectionEvent e) {
    JList list = (JList) e.getSource();
    String item = (String) source.getSelectedValue();
    System.out.println(item);//from w ww. jav a 2s  . com
    if (item != null && !item.equals("")) {
        removeFromSource(item);
        addToDestination(item);
    }
}

From source file:components.SplitPaneDemo.java

public void valueChanged(ListSelectionEvent e) {
    JList list = (JList) e.getSource();
    updateLabel(imageNames[list.getSelectedIndex()]);
}

From source file:SelectionMonitor.java

public void valueChanged(ListSelectionEvent e) {
    if ((!e.getValueIsAdjusting()) || (e.getFirstIndex() == -1))
        return;/*from   w  w  w .j a  v a 2  s  . c  o m*/

    for (int i = e.getFirstIndex(); i <= e.getLastIndex(); i++) {
        System.out.println(((JList) e.getSource()).isSelectedIndex(i));
    }
}

From source file:com.github.alexfalappa.nbspringboot.navigator.RequestMappingNavigatorPanel.java

/**
 * public no arg constructor needed for system to instantiate provider well
 *//*www  .  ja va  2  s  .c o  m*/
public RequestMappingNavigatorPanel() {
    table = new ETable();
    mappedElementsModel = new MappedElementsModel();
    mappedElementGatheringTaskFactory = new ElementScanningTaskFactory(table, mappedElementsModel);
    table.setModel(mappedElementsModel);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setColumnSorted(0, true, 1);
    table.setDefaultRenderer(RequestMethod.class, new RequestMethodCellRenderer());
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent event) {
            final int selectedRow = ((ListSelectionModel) event.getSource()).getMinSelectionIndex();
            if (event.getValueIsAdjusting() || selectedRow < 0) {
                return;
            }
            final MappedElement mappedElement = mappedElementsModel
                    .getElementAt(table.convertRowIndexToModel(selectedRow));
            ElementOpen.open(mappedElement.getFileObject(), mappedElement.getHandle());
            try {
                final DataObject dataObject = DataObject.find(mappedElement.getFileObject());
                final EditorCookie editorCookie = dataObject.getLookup().lookup(EditorCookie.class);
                if (editorCookie != null) {
                    editorCookie.openDocument();
                    JEditorPane[] p = editorCookie.getOpenedPanes();
                    if (p.length > 0) {
                        p[0].requestFocus();
                    }
                }
            } catch (IOException e) {
            }
        }
    });
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(new JScrollPane(table), BorderLayout.CENTER);
    this.component = panel;
    this.contextListener = new LookupListener() {
        @Override
        public void resultChanged(LookupEvent le) {
        }
    };
}

From source file:gui.TraitViewerDialog.java

public void processTableClick(ListSelectionEvent e) {
    ListSelectionModel lsm = (ListSelectionModel) e.getSource();
    if (lsm.isSelectionEmpty() == true)
        return;//from  w w  w  . j  a  va  2 s  .  c  o m
    int selectedRow = lsm.getMinSelectionIndex();
    splits.setRightComponent(getChart(selectedRow));

}

From source file:gui.TraitViewerDialog.java

public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting())
        return;//from  ww w.  j a va 2s  . c o  m

    if (e.getSource() == table.getSelectionModel())
        processTableClick(e);
}

From source file:SplitPaneDemo2.java

public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting())
        return;//from   ww w .j  a va2s. co  m

    JList theList = (JList) e.getSource();
    if (theList.isSelectionEmpty()) {
        label.setText("Nothing selected.");
    } else {
        int index = theList.getSelectedIndex();
        label.setText("Selected image number " + index);
    }
}

From source file:kenh.xscript.elements.Debug.java

@Override
public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting())
        return;/*  w w  w  . j  ava  2  s  .c o m*/

    Object obj = e.getSource();
    if (obj instanceof JList) {
        list((JList) obj);
    }
}

From source file:SplitPaneDemo2.java

public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting())
        return;// ww  w  . j  a  va  2 s.c o  m

    JList theList = (JList) e.getSource();
    if (theList.isSelectionEmpty()) {
        picture.setIcon(null);
        picture.setText(null);
    } else {
        int index = theList.getSelectedIndex();
        ImageIcon newImage = createImageIcon("images/" + (String) imageNames.elementAt(index));
        picture.setIcon(newImage);
        if (newImage != null) {
            picture.setText(null);
        } else {
            picture.setText("Image not found: " + (String) imageNames.elementAt(index));
        }
    }
}

From source file:Main.java

public Main() {
    super(new GridLayout(1, 0));

    final String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };

    final Object[][] data = { { "Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false) },
            { "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) },
            { "Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false) },
            { "Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true) },
            { "Philip", "Milne", "Pool", new Integer(10), new Boolean(false) } };

    final JTable table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);/*from  w  ww . ja  va  2 s . co  m*/

    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    if (ALLOW_ROW_SELECTION) { // true by default
        ListSelectionModel rowSM = table.getSelectionModel();
        rowSM.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                // Ignore extra messages.
                if (e.getValueIsAdjusting())
                    return;

                ListSelectionModel lsm = (ListSelectionModel) e.getSource();
                if (lsm.isSelectionEmpty()) {
                    System.out.println("No rows are selected.");
                } else {
                    int selectedRow = lsm.getMinSelectionIndex();
                    System.out.println("Row " + selectedRow + " is now selected.");
                }
            }
        });
    } else {
        table.setRowSelectionAllowed(false);
    }

    if (ALLOW_COLUMN_SELECTION) { // false by default
        if (ALLOW_ROW_SELECTION) {
            // We allow both row and column selection, which
            // implies that we *really* want to allow individual
            // cell selection.
            table.setCellSelectionEnabled(true);
        }
        table.setColumnSelectionAllowed(true);
        ListSelectionModel colSM = table.getColumnModel().getSelectionModel();
        colSM.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                // Ignore extra messages.
                if (e.getValueIsAdjusting())
                    return;

                ListSelectionModel lsm = (ListSelectionModel) e.getSource();
                if (lsm.isSelectionEmpty()) {
                    System.out.println("No columns are selected.");
                } else {
                    int selectedCol = lsm.getMinSelectionIndex();
                    System.out.println("Column " + selectedCol + " is now selected.");
                }
            }
        });
    }

    if (DEBUG) {
        table.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                printDebugData(table);
            }
        });
    }

    // Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    // Add the scroll pane to this panel.
    add(scrollPane);
}