Example usage for java.awt Component getName

List of usage examples for java.awt Component getName

Introduction

In this page you can find the example usage for java.awt Component getName.

Prototype

public String getName() 

Source Link

Document

Gets the name of the component.

Usage

From source file:Main.java

public void focusGained(FocusEvent evt) {

    Component c = evt.getOppositeComponent();
    System.out.println(c.getName());
}

From source file:Main.java

public void focusLost(FocusEvent evt) {

    Component c = evt.getOppositeComponent();
    System.out.println(c.getName() + "Opposite Component");
}

From source file:org.robotframework.swing.chooser.ByNameComponentChooser.java

public boolean checkComponent(Component comp) {
    return ObjectUtils.nullSafeEquals(comp.getName(), componentName);
}

From source file:Main.java

public Main() {
    comboBox = new JComboBox(new String[] { "Select Pet", "Bird", "Cat", "Dog", "Rabbit", "Pig", "Other" });
    add(comboBox, BorderLayout.PAGE_START);
    JFrame frame = new JFrame("Main");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(comboBox);/*from   w  w w .  j  a  v  a2 s.  c o  m*/
    frame.pack();
    frame.setVisible(true);

    comboBox.showPopup();
    Object child = comboBox.getAccessibleContext().getAccessibleChild(0);
    BasicComboPopup popup = (BasicComboPopup) child;
    popup.setName("BasicComboPopup");
    JList list = popup.getList();
    Container c = SwingUtilities.getAncestorOfClass(JScrollPane.class, list);
    JScrollPane scrollPane = (JScrollPane) c;

    Window mainFrame = SwingUtilities.windowForComponent(comboBox);

    System.out.println(mainFrame.getName());
    Window popupWindow = SwingUtilities.windowForComponent(popup);
    System.out.println(popupWindow);
    Window popupWindowa = SwingUtilities.windowForComponent(c);
    System.out.println(popupWindowa);

    Window mainFrame1 = SwingUtilities.getWindowAncestor(comboBox);

    System.out.println(mainFrame1);
    Window popupWindow1 = SwingUtilities.getWindowAncestor(popup);
    System.out.println(popupWindow1);

    Component mainFrame2 = SwingUtilities.getRoot(comboBox);

    System.out.println(mainFrame2.getName());
    Component popupWindow2 = SwingUtilities.getRoot(popup);
    System.out.println(popupWindow2);

    if (popupWindow != mainFrame) {
        popupWindow.pack();
    }
}

From source file:com.quinsoft.zeidon.objectbrowser.WindowBoundsRestorer.java

private void getBounds(String key, Component c) {
    key = key + c.getName();
    String position = String.format("%d,%d,%d,%d", c.getX(), c.getY(), c.getWidth(), c.getHeight());
    properties.setProperty(key, position);
    if (c instanceof Container) {
        key = key + "/";
        Container container = (Container) c;
        for (Component child : container.getComponents())
            getBounds(key, child);/*  w  w  w .  j  a  v  a2 s. c  o  m*/
    }
}

From source file:org.zaproxy.zap.extension.brk.PopupMenuAddBreakHistory.java

@Override
public boolean isEnableForComponent(Component invoker) {

    if (invoker.getName() != null && invoker.getName().equals("ListLog")) {
        try {//from   ww  w . ja va  2s. c  o m
            JList list = (JList) invoker;
            listLog = list;
            Object[] obj = listLog.getSelectedValues();

            if (obj.length == 1 && extension.canAddBreakPoint()) {
                this.setEnabled(true);
            } else {
                this.setEnabled(false);
            }

        } catch (Exception e) {
            log.warn(e.getMessage(), e);
        }
        return true;

    }
    return false;
}

From source file:Main.java

public void propertyChange(PropertyChangeEvent evt) {
    Component oldComp = (Component) evt.getOldValue();
    Component newComp = (Component) evt.getNewValue();

    if ("focusOwner".equals(evt.getPropertyName())) {
        if (oldComp == null) {
            System.out.println(newComp.getName());
        } else {//from w  w w  . j ava2 s  .c  o m
            System.out.println(oldComp.getName());
        }
    } else if ("focusedWindow".equals(evt.getPropertyName())) {
        if (oldComp == null) {
            System.out.println(newComp.getName());
        } else {
            System.out.println(oldComp.getName());
        }
    }
}

From source file:com.quinsoft.zeidon.objectbrowser.WindowBoundsRestorer.java

private void setBounds(String key, Component c) {
    key = key + c.getName();

    String position = properties.getProperty(key);
    if (c.getName() != null && !StringUtils.isBlank(position)) {
        String[] nums = position.split(",");
        c.setBounds(Integer.parseInt(nums[0]), Integer.parseInt(nums[1]), Integer.parseInt(nums[2]),
                Integer.parseInt(nums[3]));
    }/*from  ww w .  j a  va 2 s.c om*/

    if (c instanceof Container) {
        key = key + "/";
        Container container = (Container) c;
        for (Component child : container.getComponents())
            setBounds(key, child);
    }
}

From source file:Main.java

public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
    Component oldComp = (Component) evt.getOldValue();
    Component newComp = (Component) evt.getNewValue();

    if ("focusOwner".equals(evt.getPropertyName())) {
        if (oldComp == null) {
            System.out.println(newComp.getName());
        } else {//w w  w.j ava  2 s . c  o m
            System.out.println(oldComp.getName());
        }
    } else if ("focusedWindow".equals(evt.getPropertyName())) {
        if (oldComp == null) {
            System.out.println(newComp.getName());
        } else {
            System.out.println(oldComp.getName());
        }
    }

    boolean vetoFocusChange = false;
    if (vetoFocusChange) {
        throw new PropertyVetoException("message", evt);
    }
}

From source file:net.sf.nmedit.jtheme.component.misc.CallDescriptor.java

private JTComponent getTarget() {
    if (target == null) {
        Container c = owner.getParent();
        if (c != null) {
            for (int i = c.getComponentCount() - 1; i >= 0; i--) {
                Component t = c.getComponent(i);
                if (t instanceof JTComponent && component.equals(t.getName())) {
                    target = (JTComponent) t;
                    break;
                }/*  www .j  a v  a 2  s  . com*/
            }
        }
    }
    return target;
}