Java JComponent Container getModelObject(JComponent c)

Here you can find the source of getModelObject(JComponent c)

Description

get Model Object

License

Open Source License

Declaration

protected static Object getModelObject(JComponent c) 

Method Source Code

//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;
    }
}

Related

  1. getInsetBounds(JComponent comp)
  2. getInterior(JComponent comp)
  3. getLocalInsetBounds(JComponent component)
  4. getMandatoryPanel(JComponent c)
  5. getMaxVisibleY(JComponent comp)
  6. getOutermostRootPane(Component c)
  7. getOutermostRootPane(Component c)
  8. getPanelFor(JComponent comp1, JComponent comp2)
  9. getPanelFor(JComponent comp1, JComponent comp2)