Java 8 ListSelectionEvent - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ListSelectionEvent class.

This code example shows how to use the following methods:getSource, getValueIsAdjusting
	return names.get(index);
    } 
 
    @Override 
    public void valueChanged(ListSelectionEvent e) {
	Object source = e.getSource();
	if (! e.getValueIsAdjusting() && source instanceof JList) {
	    JList sourceList = (JList) source;
	    // save last displayed component 
	    saveLastDialog(); 
	    // load other panel if an index is selected 
	    int idx = sourceList.getSelectedIndex();
	    if (idx >= 0) {
		AddonPanel panel = getPanel(idx);
		lastActivePanel = panel;
		container.removeAll();
		container.add(panel, BorderLayout.CENTER);
		// invalidate component, else it won't be redrawn 
		container.invalidate();
		container.validate();
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addListSelectionListener, setCellRenderer, setModel, setSelectionMode
     
    JPanel mainPanel = new JPanel();
    _frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
    mainPanel.setLayout(new BorderLayout());
     
    _viewList = new JList<ViewEntry>();
    _viewListModel = getViewListModel();
    _viewList.setModel(_viewListModel);
    _viewList.setCellRenderer(getViewListCellRenderer());
    _viewList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 
    final ConfigSource configSource = getToolContext().getConfigSource();
    final PositionSource positionSource = getToolContext().getPositionSource();
    final SecuritySource securitySource = getToolContext().getSecuritySource();
     
     
    JPanel panel = new JPanel();
    mainPanel.add(panel, BorderLayout.CENTER);
    panel.setLayout(new BorderLayout(0, 0));
     

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCellBounds, getSelectedIndex, locationToIndex, setSelectedIndex
            return; 
        } 
 
        ActionList actions = null;
        JList list = (JList) e.getSource();
        int row = list.locationToIndex(e.getPoint());
        if (row == -1 || !list.getCellBounds(row, row).contains(e.getPoint())) {
            if (list.getSelectedIndex() != -1) {
                list.clearSelection();
            } 
 
            actions = getDefaultActions();
        } else { 
            if (list.getSelectedIndex() != row) {
                list.setSelectedIndex(row);
            } 
 
            actions = getActionsForRow(list, row);
        } 
 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getFont, getForeground, getSelectionBackground, getSelectionForeground
	public Component getListCellRendererComponent(JList list, Object value, int i, boolean selected, boolean focused) {
 
		Webcam webcam = (Webcam) value;
 
		if (selected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else { 
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		} 
 
		setText(webcam.getName());
		setFont(list.getFont());
 
		return this;
	} 
 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:ensureIndexIsVisible, getSelectedIndex, getSelectedIndices, setSelectedIndex
   * JList 
   */ 
  protected void setButtons(ListSelectionEvent e) {
    if ( (e == null) || (e.getSource() == m_Info) ) {
      m_ButtonClear.setEnabled(m_Model.getSize() > 0);
      m_ButtonCopy.setEnabled(m_Info.getSelectedIndices().length == 1);
    } 
  } 
 
  /** 
   * sets the focus in a designated control 
   */ 
  public void setFocus() { 
    m_Info.requestFocus();
  } 
 
  /** 
   * clears the content of the panel 
   */ 
  public void clear() { 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getFont, getForeground, isEnabled, getSelectionBackground
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getForeground, getSelectionBackground, getSelectionForeground
	 */ 
	public Component getListCellRendererComponent(final JList list, final Object value, final int index,
	                                              final boolean isSelected, final boolean cellHasFocus) {
		Component cellRendererComponent = getCellRendererComponent(value, isSelected);
        if (isSelected) {
        	cellRendererComponent.setBackground(list.getSelectionBackground());
        	cellRendererComponent.setForeground(list.getSelectionForeground());
        } 
        else { 
        	cellRendererComponent.setBackground(list.getBackground());
        	cellRendererComponent.setForeground(list.getForeground());
        } 
		return cellRendererComponent;
	} 
	 
	private Component getCellRendererComponent(final Object value, final boolean isSelected) {
		final JComponent component;
		if (value == null) { 
			component =  new JLabel(noValueText);
		} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getModel, getSelectedIndices, isSelectedIndex, locationToIndex, setSelectedIndex
            menu.show(evt.getComponent(), evt.getX(), evt.getY());
        } 
    } 
 
    protected int checkListSelection(JList<?> list, Point p) {
        int idx = list.locationToIndex(p);
        if (idx >= 0 && idx < list.getModel().getSize() && list.getSelectedIndices().length < 2 && !list.isSelectedIndex(idx)) {
            list.setSelectedIndex(idx);
        } 
        return idx;
    } 
 
    protected int checkTableSelection(JTable table, Point p) {
        int row = table.rowAtPoint(p);
        if (row >= 0 && row < table.getRowCount() && table.getSelectedRowCount() < 2 && table.getSelectedRow() != row) {
            table.getSelectionModel().setSelectionInterval(row, row);
        } 
        return row;
    } 
 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getFont, getForeground, getSelectionBackground, getSelectionForeground
        return this;
    } 
 
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        if (isSelected) {
            setForeground(list.getSelectionForeground());
            setBackground(list.getSelectionBackground());
        } else { 
            setForeground(list.getForeground());
            setBackground(list.getBackground());
        } 
        setFont(list.getFont());
        if (cellHasFocus) {
            setBorder( UIManager.getBorder("List.focusCellHighlightBorder") );
            /* 
            if (list.isCellEditable(row, column)) { 
                setForeground( UIManager.getColor("List.focusCellForeground") ); 
                setBackground( UIManager.getColor("List.focusCellBackground") ); 
            } 
             */ 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setTransferHandler, setDragEnabled, setSelectionMode
See Code Examples for Java 8 ListSelectionEvent Methods: