Example usage for javax.swing JComponent getName

List of usage examples for javax.swing JComponent getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Gets the name of the component.

Usage

From source file:ItemTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();

    ItemListener listener = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            System.out.println("Source: " + name(e.getSource()));
            System.out.println("Item: " + name(e.getItem()));
            int state = e.getStateChange();
            System.out.println("State: " + ((state == ItemEvent.SELECTED) ? "Selected" : "Deselected"));
        }//from   w w  w. ja  v  a2 s. c o m

        private String name(Object o) {
            if (o instanceof JComponent) {
                JComponent comp = (JComponent) o;
                return comp.getName();
            } else {
                return o.toString();
            }
        }
    };

    JPanel panel = new JPanel(new GridLayout(0, 1));
    ButtonGroup group = new ButtonGroup();
    JRadioButton option = new JRadioButton("French Fries", true);
    option.setName(option.getText());
    option.addItemListener(listener);
    group.add(option);
    panel.add(option);
    option = new JRadioButton("Onion Rings", false);
    option.setName(option.getText());
    option.addItemListener(listener);
    group.add(option);
    panel.add(option);
    option = new JRadioButton("Ice Cream", false);
    option.setName(option.getText());
    option.addItemListener(listener);
    group.add(option);
    panel.add(option);
    contentPane.add(panel, BorderLayout.NORTH);

    String flavors[] = { "Item 1", "Item 2", "Item 3" };
    JComboBox jc = new JComboBox(flavors);
    jc.setName("Combo");
    jc.addItemListener(listener);
    jc.setMaximumRowCount(4);
    contentPane.add(jc, BorderLayout.SOUTH);

    frame.pack();
    frame.show();
}

From source file:Main.java

public static void printTree(JComponent c, int tabs) {
    if (c.getName() != null && !c.getName().contains("null") || tabs == 0) {
        for (int i = 0; i < tabs; i++)
            System.out.print(" ");
        System.out.println(c.getName() + " [" + c.getClass().getSimpleName() + "]");
    } else//from w w w . jav a2 s. c  o m
        tabs--;

    if (c.getComponents() == null)
        return;
    for (Component ci : c.getComponents()) {
        if (ci instanceof JComponent)
            printTree((JComponent) ci, tabs + 1);
    }
}

From source file:Main.java

public static JComponent match(JComponent c, final String name) {
    if (c.getName() != null && c.getName().contains(name))
        return c;
    for (Component ci : c.getComponents()) {
        if (ci instanceof JComponent) {
            JComponent ret = match((JComponent) ci, name);
            if (ret != null)
                return ret;
        }/*from   w w  w.  ja v  a2s .  co m*/
    }
    return null;
}

From source file:Main.java

public static JComponent getComponentByName(Container parent, String name) {
    Collection components = getAllJComponents(parent);
    for (Iterator iterator = components.iterator(); iterator.hasNext();) {
        JComponent component = (JComponent) iterator.next();
        if (name.equals(component.getName()))
            return component;
    }/*from ww w. j a  v  a  2  s. com*/
    return null;
}

From source file:com.croer.javaorange.diviner.SimpleOrangeDiviner.java

@Override
public void show(JComponent jComponent) {
    this.jComponent = jComponent;
    System.out.println(configuration.getString(jComponent.getName()));
    Point location = jComponent.getLocationOnScreen();
    Dimension size = jComponent.getSize();
    Point xy = new Point(location.x, location.y + size.height);

    setLocation(xy);//from w  w  w.j a v  a  2  s.  com
    //        EventQueue.invokeLater(new Runnable() {
    //
    //            public void run() {
    //                jTextField3.requestFocusInWindow();
    //            }
    //        });
    pack();
    setVisible(true);
}

From source file:eu.ggnet.dwoss.receipt.unit.UnitView.java

private void updateValidationStatus(JComponent component, Survey vs, StringBuilder sb) {
    EventQueue.invokeLater(() -> {
        component.setToolTipText(vs.getMessage());
        component.setForeground(vs.getStatus().getColor());
    });// ww w .j a va2  s . com
    sb.append("- ").append(component.getName()).append(": ").append(vs.getStatus()).append(" : ")
            .append(vs.getMessage()).append("\n");
}

From source file:net.sourceforge.squirrel_sql.fw.gui.debug.DebugEventListener.java

private void setToolTipText(JComponent source, AWTEvent event) {

    Container parent = source.getParent();
    String sourceName = source.getName();
    String sourceClassName = source.getClass().toString();
    String parentClassName = parent == null ? null : parent.getClass().toString();

    StringBuilder toolTipText = new StringBuilder(getEventMessagePrefix(event));

    if (source instanceof AbstractButton) {
        toolTipText.append("Button with parentClass=");
        toolTipText.append(parentClassName);
    } else {//from www  .  j  a v  a  2  s  .co m
        if (!StringUtils.isEmpty(sourceName)) {
            toolTipText.append(sourceName);
        } else if (!StringUtils.isEmpty(sourceClassName)) {
            toolTipText.append(sourceClassName);
        }
    }
    source.setToolTipText(toolTipText.toString());
}

From source file:net.sourceforge.squirrel_sql.fw.gui.debug.DebugEventListener.java

private void printDebugInfo(JComponent source, AWTEvent event) {
    Container parent = source.getParent();
    String sourceName = source.getName();
    String sourceClassName = source.getClass().toString();
    String parentName = parent == null ? null : parent.getName();
    String parentClassName = parent == null ? null : parent.getClass().toString();

    StringBuilder msg = new StringBuilder(getEventMessagePrefix(event));
    msg.append("\n");
    msg.append("\t sourceName:").append(sourceName).append("\n");
    msg.append("\t sourceClassName:").append(sourceClassName).append("\n");
    msg.append("\t parentName:").append(parentName).append("\n");
    msg.append("\t parentClassName:").append(parentClassName);
    System.out.println(msg.toString());
}

From source file:org.apache.log4j.chainsaw.LogUI.java

private void initPlugins(PluginRegistry pluginRegistry) {
    pluginRegistry.addPluginListener(new PluginListener() {
        public void pluginStarted(PluginEvent e) {
            if (e.getPlugin() instanceof JComponent) {
                JComponent plugin = (JComponent) e.getPlugin();
                getTabbedPane().addANewTab(plugin.getName(), plugin, null, null);
                getPanelMap().put(plugin.getName(), plugin);
            }//w  ww  . j  av  a 2 s  . c  o m
        }

        public void pluginStopped(PluginEvent e) {
            //TODO remove the plugin from the gui
        }
    });

    // TODO this should all be in a config file
    //    ChainsawCentral cc = new ChainsawCentral();
    //    pluginRegistry.addPlugin(cc);
    //    cc.activateOptions();

    try {
        Class pluginClass = Class.forName("org.apache.log4j.chainsaw.zeroconf.ZeroConfPlugin");
        Plugin plugin = (Plugin) pluginClass.newInstance();
        pluginRegistry.addPlugin(plugin);
        plugin.activateOptions();
        MessageCenter.getInstance().getLogger().info("Looks like ZeroConf is available... WooHoo!");
    } catch (Throwable e) {
        MessageCenter.getInstance().getLogger().error("Doesn't look like ZeroConf is available", e);
    }
}

From source file:org.colombbus.tangara.commons.resinject.ClassResourceImpl.java

@Override
public void inject(JComponent component) {
    Validate.notNull(component, "component argument is null"); //$NON-NLS-1$

    String key = component.getName();
    Validate.notEmpty(key, "component argument has no name"); //$NON-NLS-1$

    JComponentInjecter injecter = new JComponentInjecter();
    injecter.setClassResource(this);
    injecter.setKey(key);/*from  ww w.j ava  2 s .com*/
    injecter.setComponent(component);
    injecter.inject();
}