Component getParent - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Component getParent method.

This code example shows how to use the following methods:getParent
    * Test of getComponentWithMargin method, of class GuiBuilderHelper. 
    */ 
   @Test
   public void testGetComponentWithMargin() { 
      System.out.println("getComponentWithMargin");
      Component component = new JTextField("test");
      int top = 1;
      int left = 2;
      int bottom = 3;
      int right = 4;
      JPanel result = GuiBuilderHelper.getComponentWithMargin(component, top, left, bottom, right);
      assertTrue(component.getParent().equals(result));
   } 
 
    /** 
     * Test of strechItemToComponent method, of class GuiBuilderHelper. 
     */ 
    @Test
    public void testStrechItemToComponent() { 
        System.out.println("strechItemToComponent");
6
CodeRank
This code example shows how to use the following methods:getParent
  private @Nullable Window sourceOf(@Nonnull AWTEvent e) {
    return (Window) e.getSource();
  } 
 
  private void filter(@Nonnull Window w) {
    if (filter.isImplicitlyIgnored(w)) {
      filter.recognize(w);
      return; 
    } 
    // Catch new sub-windows of filtered windows (i.e. dialogs generated by a test harness UI). 
    filterIfParentIsFiltered(w);
  } 
 
  private void filterIfParentIsFiltered(@Nonnull Window w) {
    if (!filter.isIgnored(w.getParent())) {
      return; 
    } 
    filter.ignore(w);
  } 
} 

6
CodeRank
This code example shows how to use the following methods:getParent
 
  @RunsInCurrentThread 
  private String pathOf(@Nonnull JMenuItem menuItem) {
    Component parent = parentOrInvokerOf(menuItem);
    if (parent instanceof JMenuItem) {
      return concat(pathOf((JMenuItem) parent), SEPARATOR, textOf(menuItem));
    } 
    return textOf(menuItem);
  } 
 
  @RunsInCurrentThread 
  private Component parentOrInvokerOf(@Nonnull JMenuItem menuItem) {
    Component parent = menuItem.getParent();
    if (parent instanceof JPopupMenu) {
      parent = ((JPopupMenu) parent).getInvoker();
    } 
    return parent;
  } 
 
  @Override 
6
CodeRank
This code example shows how to use the following methods:getParent, getSize, setBounds
     * @param verticalPercent  the relative location. 
     */ 
    public static void positionDialogRelativeToParent(final Dialog dialog,
                                                      final double horizontalPercent,
                                                      final double verticalPercent) {
      final Container parent = dialog.getParent();
      if (parent == null)
      { 
        centerFrameOnScreen(dialog);
        return; 
      } 
 
      final Dimension d = dialog.getSize();
      final Dimension p = parent.getSize();
 
      final int baseX = parent.getX();
      final int baseY = parent.getY();
 
      final int x = baseX + (int) (horizontalPercent * p.width);
      final int y = baseY + (int) (verticalPercent * p.height);

6
CodeRank
This code example shows how to use the following methods:getParent, getX, getY
 * @author Yvonne Wang 
 */ 
final class PointAndParentForScrollingJTextFieldQuery { 
  @RunsInCurrentThread 
  static @Nonnull Pair<Point, Container> pointAndParentForScrolling(final @Nonnull JTextField textField) {
    Point origin = new Point(textField.getX(), textField.getY());
    Container parent = textField.getParent();
    while (parent != null && !(parent instanceof JComponent) && !(parent instanceof CellRendererPane)) {
      origin = addRectangleToPoint(checkNotNull(parent.getBounds()), origin);
      parent = parent.getParent();
    } 
    return Pair.of(origin, parent);
  } 
 
  private static @Nonnull Point addRectangleToPoint(@Nonnull Rectangle r, @Nonnull Point p) {
    Point newPoint = new Point(p);
    newPoint.x += r.x;
    newPoint.y += r.y;
    return newPoint;
  } 
6
CodeRank
This code example shows how to use the following methods:getParent, getSize, setBounds
     * @param horizontalPercent  the relative location. 
     * @param verticalPercent  the relative location. 
     */ 
    public static void positionDialogRelativeToParent(Dialog dialog, 
            double horizontalPercent, double verticalPercent) {
        Container parent = dialog.getParent();
        if (parent == null) {
            centerFrameOnScreen(dialog);
            return; 
        } 
 
        Dimension d = dialog.getSize();
        Dimension p = parent.getSize();
 
        int baseX = parent.getX();
        int baseY = parent.getY();
 
        int x = baseX + (int) (horizontalPercent * p.width);
        int y = baseY + (int) (verticalPercent * p.height);
 

6
CodeRank
This code example shows how to use the following methods:getParent, setBorderPainted
     * @param e  the mouse event. 
     */ 
    public void mouseExited(final MouseEvent e) {
        if (e.getSource() instanceof AbstractButton) {
            final AbstractButton button = (AbstractButton) e.getSource();
            button.setBorderPainted(false);
            if (button.getParent() != null)
            { 
//                button.getParent().repaint(button.getX(), button.getY(), 
//                    button.getWidth(), button.getHeight()); 
                button.getParent().repaint();
            } 
        } 
    } 
 
} 
5
CodeRank
This code example shows how to use the following methods:getParent, getSize, setBounds
   */ 
  public static void positionDialogRelativeToParent(final Dialog dialog,
                                                    final double horizontalPercent,
                                                    final double verticalPercent)
  { 
    final Container parent = dialog.getParent();
    if (parent == null || (parent.isVisible() == false))
    { 
      positionFrameOnScreen(dialog, horizontalPercent, verticalPercent);
      return; 
    } 
 
    final Dimension d = dialog.getSize();
    final Dimension p = parent.getSize();
 
    final int baseX = parent.getX();
    final int baseY = parent.getY();
 
    final int parentPointX = baseX + (int) (horizontalPercent * p.width);
    final int parentPointY = baseY + (int) (verticalPercent * p.height);

5
CodeRank
This code example shows how to use the following methods:getParent, getWidth
This code example shows how to use the following methods:getParent, getSize, setBounds
   */ 
  public static void positionDialogRelativeToParent(final Dialog dialog,
                                                    final double horizontalPercent,
                                                    final double verticalPercent)
  { 
    final Container parent = dialog.getParent();
    if (parent == null || (parent.isVisible() == false))
    { 
      positionFrameOnScreen(dialog, horizontalPercent, verticalPercent);
      return; 
    } 
 
    final Dimension d = dialog.getSize();
    final Dimension p = parent.getSize();
 
    final int baseX = parent.getX();
    final int baseY = parent.getY();
 
    final int parentPointX = baseX + (int)(horizontalPercent * p.width);
    final int parentPointY = baseY + (int)(verticalPercent * p.height);

5
CodeRank
getParent Method Overview
Gets the parent of this component.
See Code Examples for other Java 8 Component Methods: