Example usage for javax.swing JComponent getMouseListeners

List of usage examples for javax.swing JComponent getMouseListeners

Introduction

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

Prototype

public synchronized MouseListener[] getMouseListeners() 

Source Link

Document

Returns an array of all the mouse listeners registered on this component.

Usage

From source file:Main.java

private static void disposeComponent(JComponent component) {
    if (component == null) {
        return;/*from  ww w.j  a va 2s.com*/
    }
    component.removeNotify();
    FocusListener[] focusListeners = component.getFocusListeners();
    for (int i = 0; i < focusListeners.length; i++) {
        component.removeFocusListener(focusListeners[i]);
    }
    KeyListener[] keyListeners = component.getKeyListeners();
    for (int i = 0; i < keyListeners.length; i++) {
        component.removeKeyListener(keyListeners[i]);
    }
    AncestorListener[] ancestorListener = component.getAncestorListeners();
    for (int i = 0; i < ancestorListener.length; i++) {
        component.removeAncestorListener(ancestorListener[i]);
    }
    ComponentListener[] componentListeners = component.getComponentListeners();
    for (int i = 0; i < componentListeners.length; i++) {
        component.removeComponentListener(componentListeners[i]);
    }
    HierarchyListener[] hierarchyListeners = component.getHierarchyListeners();
    for (int i = 0; i < hierarchyListeners.length; i++) {
        component.removeHierarchyListener(hierarchyListeners[i]);
    }
    HierarchyBoundsListener[] hierarchyBoundsListeners = component.getHierarchyBoundsListeners();
    for (int i = 0; i < hierarchyBoundsListeners.length; i++) {
        component.removeHierarchyBoundsListener(hierarchyBoundsListeners[i]);
    }
    InputMethodListener[] inputMethodListeners = component.getInputMethodListeners();
    for (int i = 0; i < inputMethodListeners.length; i++) {
        component.removeInputMethodListener(inputMethodListeners[i]);
    }
    MouseListener[] mouseLisetners = component.getMouseListeners();
    for (int i = 0; i < mouseLisetners.length; i++) {
        component.removeMouseListener(mouseLisetners[i]);
    }
    MouseMotionListener[] mouseMotionLisetners = component.getMouseMotionListeners();
    for (int i = 0; i < mouseMotionLisetners.length; i++) {
        component.removeMouseMotionListener(mouseMotionLisetners[i]);
    }
    MouseWheelListener[] mouseWheelListeners = component.getMouseWheelListeners();
    for (int i = 0; i < mouseWheelListeners.length; i++) {
        component.removeMouseWheelListener(mouseWheelListeners[i]);
    }
    PropertyChangeListener[] propertyChangeListeners = component.getPropertyChangeListeners();
    for (int i = 0; i < propertyChangeListeners.length; i++) {
        component.removePropertyChangeListener(propertyChangeListeners[i]);
    }
    VetoableChangeListener[] vetoableChangeListener = component.getVetoableChangeListeners();
    for (int i = 0; i < vetoableChangeListener.length; i++) {
        component.removeVetoableChangeListener(vetoableChangeListener[i]);
    }

}

From source file:org.datacleaner.widgets.table.DCTableCellRenderer.java

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    logger.debug("getTableCellRendererComponent({},{})", row, column);

    if (value != null) {
        if (value.getClass().isArray()) {
            // arrays are printed nicely this way
            value = ArrayUtils.toString(value);
        }//from w  ww . ja va  2s  . c o m
    }

    // icons are displayed as labels
    if (value instanceof Icon) {
        final JLabel label = new JLabel((Icon) value);
        label.setOpaque(true);
        value = label;
    }

    final Component result;

    // render components directly
    if (value instanceof JComponent) {
        final JComponent component = (JComponent) value;

        component.setOpaque(true);

        if (component.getMouseListeners().length == 0) {
            component.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    MouseEvent newEvent = SwingUtilities.convertMouseEvent(component, e, _table);
                    _table.consumeMouseClick(newEvent);
                }
            });
        }

        result = component;
    } else {
        result = _delegate.getTableCellRendererComponent(_table, value, isSelected, hasFocus, row, column);
        assert result instanceof JLabel;
    }

    // alignment is applied to all labels or panels (with flowlayout)
    Alignment alignment = _alignmentOverrides.get(column);
    if (alignment == null) {
        alignment = Alignment.LEFT;
    }

    // set alignment
    if (value instanceof JPanel) {
        final LayoutManager layout = ((JPanel) value).getLayout();
        if (layout instanceof FlowLayout) {
            final FlowLayout flowLayout = (FlowLayout) layout;
            flowLayout.setAlignment(alignment.getFlowLayoutAlignment());
        }
    } else if (result instanceof JLabel) {
        final JLabel label = (JLabel) result;
        label.setHorizontalAlignment(alignment.getSwingContstantsAlignment());

        WidgetUtils.setAppropriateFont(label);
    }

    return result;
}