java.awt.Window.getOwner()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中java.awt.Window.getOwner()方法的一些代码示例,展示了Window.getOwner()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window.getOwner()方法的具体详情如下:
包路径:java.awt.Window
类名称:Window
方法名:getOwner

Window.getOwner介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

super.done();
dialog.dispose();
JOptionPane.showMessageDialog(dialog.getOwner(), "Message sent", "Success", JOptionPane.INFORMATION_MESSAGE);

代码示例来源:origin: net.sf.tinylaf/tinylaf

private Window getOwningFrame(Dialog dialog) {
  while(true) {
    Window w = ((Dialog)dialog).getOwner();
    
    if(w == null) return w;
    
    if(!(w instanceof Dialog)) return w;
    
    dialog = (Dialog)w;
  }
}

代码示例来源:origin: xyz.cofe/docking-frames-core

/**
 * Tells whether <code>parent</code> is really a parent of <code>child</code>
 * or not.
 * @param parent a window which may be an ancestor of <code>child</code>
 * @param child a window which may be child of <code>parent</code>
 * @return <code>true</code> if <code>parent</code> is an
 * ancestor of <code>child</code>
 */
private boolean isParent( Window parent, Window child ){
  Window temp = child.getOwner();
  while( temp != null ){
    if( temp == parent )
      return true;
    
    temp = temp.getOwner();
  }
  
  return false;
}

代码示例来源:origin: org.opentcs.thirdparty.dockingframes/docking-frames-core

/**
 * Tells whether <code>parent</code> is really a parent of <code>child</code>
 * or not.
 * @param parent a window which may be an ancestor of <code>child</code>
 * @param child a window which may be child of <code>parent</code>
 * @return <code>true</code> if <code>parent</code> is an
 * ancestor of <code>child</code>
 */
private boolean isParent( Window parent, Window child ){
  Window temp = child.getOwner();
  while( temp != null ){
    if( temp == parent )
      return true;
    
    temp = temp.getOwner();
  }
  
  return false;
}

代码示例来源:origin: de.richtercloud/flexdock-core

public Window getOwner() {
  Component root = getRootContainer();
  if (root instanceof JFrame) {
    return ((Window) root).getOwner();
  } else if (root instanceof JWindow) {
    return ((Window) root).getOwner();
  } else if (root instanceof JDialog) {
    return ((Window) root).getOwner();
  }
  return null;
}

代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-common

private static boolean isUnowned(Window window) {
  return window.getOwner() == null || (window instanceof JDialog && JOptionPane.getRootFrame().equals(window.getOwner()));
}

代码示例来源:origin: org.swinglabs.swingx/swingx-all

private static boolean isUnowned(Window window) {
  return window.getOwner() == null || (window instanceof JDialog && JOptionPane.getRootFrame().equals(window.getOwner()));
}

代码示例来源:origin: tmyroadctfig/swingx

private static boolean isUnowned(Window window) {
  return window.getOwner() == null || (window instanceof JDialog && JOptionPane.getRootFrame().equals(window.getOwner()));
}

代码示例来源:origin: org.apache.cayenne.modeler/cayenne-modeler

/**
   * "Injects" windows's content to parent window
   */
  public static void dock(Window window) {
    dock(window, window.getOwner());
  }
}

代码示例来源:origin: net.sf.doolin/doolin-gui

/**
 * @see Window#setLocationRelativeTo(java.awt.Component)
 * @see Window#getOwner()
 */
@Override
public void setLocation() {
  this.window.setLocationRelativeTo(this.window.getOwner());
}

代码示例来源:origin: notzippy/JALOPY2-MAIN

/**
 * Returns the frame that contains the given component.
 *
 * @param component component.
 *
 * @return frame that contains the given component or <code>null</code> if there is
 *         no parent frame.
 */
public static Frame getOwnerFrame(Component component)
{
  Window window = SwingUtilities.windowForComponent(component);
  Frame mother = null;
  if (window != null)
  {
    Window owner = window.getOwner();
    if ((owner != null) && owner instanceof Frame)
    {
      mother = (Frame) owner;
    }
  }
  return mother;
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

private static Rectangle getUsableDeviceBounds(Window window) {
  Window owner = window.getOwner();
  GraphicsConfiguration gc = null;
  
  if (owner == null) {
    gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
        .getDefaultScreenDevice().getDefaultConfiguration();
  } else {
    gc = owner.getGraphicsConfiguration();
  }
  
  Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
  Rectangle bounds = gc.getBounds();
  bounds.x += insets.left;
  bounds.y += insets.top;
  bounds.width -= (insets.left + insets.right);
  bounds.height -= (insets.top + insets.bottom);
  
  return bounds;
}

代码示例来源:origin: org.gosu-lang.gosu/gosu-lab

private static Frame getFrameWindow()
{
 Window activeWindow = EditorUtilities.getActiveWindow();
 if( activeWindow == null )
 {
  return getActiveFrameFromApp();
 }
 if( activeWindow instanceof Frame )
 {
  return (Frame)activeWindow;
 }
 return (Frame)activeWindow.getOwner();
}

代码示例来源:origin: stackoverflow.com

import java.lang.ref.WeakReference;

import javax.swing.JDialog;
import javax.swing.JFrame;

public class Test {

public static void main(String[] args) throws Throwable {
  WeakReference<JDialog> ref = test();

  Runtime.getRuntime().gc();
  System.out.println(ref.get()==null? "collected": "still flying around");
 }

 public static WeakReference<JDialog> test() throws Throwable {
   JDialog d = new JDialog(new JFrame());
   WeakReference<JDialog> ref = new WeakReference<JDialog>(d);
   d.setVisible(true);
   d.dispose();
   d.getOwner().dispose();
   return ref;
 }
}

代码示例来源:origin: com.github.insubstantial/substance

/**
 * Returns the component hierarchy.
 * 
 * @param comp
 *            Component.
 * @return Component hierarchy string.
 */
public static String getHierarchy(Component comp) {
  StringBuffer buffer = new StringBuffer();
  getHierarchy(comp, buffer, 0);
  while (true) {
    if (comp instanceof Window) {
      Window w = (Window) comp;
      comp = w.getOwner();
      if (comp != null) {
        buffer.append("Owner --->\n");
        getHierarchy(comp, buffer, 0);
      }
    } else {
      break;
    }
  }
  return buffer.toString();
}

代码示例来源:origin: icza/scelight

window.setLocationRelativeTo( window.getOwner() );

代码示例来源:origin: stackoverflow.com

import java.awt.Window;

import javax.swing.JFrame;
import javax.swing.JDialog;

public class WhyNoDispose extends JDialog {
  public static void main(String[] args) {
   javax.swing.SwingUtilities.invokeLater(new Runnable() {
     public void run() {
      try {
        WhyNoDispose frame = new WhyNoDispose("my title");
        frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        JFrame win = (JFrame) frame.getOwner();
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        win.dispose();
        // System.exit(0);
      } catch (Exception e) {
        e.printStackTrace();
      }
     }
   });
  }

  public WhyNoDispose(String title) {
   super(new JFrame(title), ModalityType.APPLICATION_MODAL);
   pack();
  }
}

代码示例来源:origin: com.github.insubstantial/substance

/**
 * Updates the application icon.
 */
private void updateAppIcon() {
  Window window = getWindow();
  if (window == null) {
    this.appIcon = null;
    return;
  }
  this.appIcon = null;
  while (window != null && appIcon == null) {
    java.util.List<Image> icons = window.getIconImages();
    if (icons.size() == 0) {
      window = window.getOwner();
    } else {
      int prefSize = SubstanceSizeUtils.getTitlePaneIconSize();
      this.appIcon = SubstanceCoreUtilities.getScaledIconImage(icons,
          prefSize, prefSize);
    }
  }
}

代码示例来源:origin: de.richtercloud/flexdock-core

public static DockingFrame create(Component c, String groupName) {
  RootWindow rootWin = RootWindow.getRootContainer(c);
  Component window = rootWin.getRootContainer();
  if (window instanceof DockingFrame) {
    window = ((Window) window).getOwner();
  }
  //Applets are actually contained in a frame
  if (window instanceof Applet) {
    window = SwingUtilities.windowForComponent(window);
  }
  if (window instanceof Frame) {
    return new DockingFrame((Frame) window, groupName);
  }
  if (window instanceof Dialog) {
    return new DockingFrame((Dialog) window, groupName);
  }
  return null;
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-swing-core

public static void center(final Window window) {
 if (window == null) {
  return;
 }
 final Window owner = window.getOwner();
 if (owner == null || owner.getBounds().equals(new Rectangle(0, 0, 0, 0))) {
  centerToScreen(window);
  return;
 }
 final int x = owner.getX() + owner.getWidth() / 2 - window.getWidth() / 2;
 final int y = owner.getY() + owner.getHeight() / 2 - window.getHeight() / 2;
 window.setLocation(x < 0 ? 0 : x, y < 0 ? 0 : y);
}

相关文章

Window类方法