Here you can find the source of getModelObject(JComponent c)
protected static Object getModelObject(JComponent c)
//package com.java2s; /**/*from ww w . j a va 2 s. c o m*/ * DataCleaner (community edition) * Copyright (C) 2014 Neopost - Customer Information Management * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ import javax.swing.JComponent; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; public class Main { protected static Object getModelObject(JComponent c) { if (c instanceof JTree) { final TreePath path = ((JTree) c).getSelectionPath(); final Object pathComponent = path.getLastPathComponent(); if (pathComponent instanceof DefaultMutableTreeNode) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathComponent; final Object userObject = node.getUserObject(); return userObject; } } return null; } }