List of usage examples for java.awt Container getWidth
public int getWidth()
From source file:LCBLayout.java
/** * Lays out the components./*from w w w .j a v a 2 s .com*/ * * @param parent the parent. */ public void layoutContainer(final Container parent) { synchronized (parent.getTreeLock()) { final Insets insets = parent.getInsets(); final int ncomponents = parent.getComponentCount(); final int nrows = ncomponents / COLUMNS; for (int c = 0; c < COLUMNS; c++) { for (int r = 0; r < nrows; r++) { final Component component = parent.getComponent(r * COLUMNS + c); final Dimension d = component.getPreferredSize(); if (this.colWidth[c] < d.width) { this.colWidth[c] = d.width; } if (this.rowHeight[r] < d.height) { this.rowHeight[r] = d.height; } } } int totalHeight = this.vGap * (nrows - 1); for (int r = 0; r < nrows; r++) { totalHeight = totalHeight + this.rowHeight[r]; } final int totalWidth = this.colWidth[0] + this.colWidth[1] + this.colWidth[2]; // adjust the width of the second column to use up all of parent final int available = parent.getWidth() - insets.left - insets.right - this.labelGap - this.buttonGap; this.colWidth[1] = this.colWidth[1] + (available - totalWidth); // *** DO THE LAYOUT *** int x = insets.left; for (int c = 0; c < COLUMNS; c++) { int y = insets.top; for (int r = 0; r < nrows; r++) { final int i = r * COLUMNS + c; if (i < ncomponents) { final Component component = parent.getComponent(i); final Dimension d = component.getPreferredSize(); final int h = d.height; final int adjust = (this.rowHeight[r] - h) / 2; parent.getComponent(i).setBounds(x, y + adjust, this.colWidth[c], h); } y = y + this.rowHeight[r] + this.vGap; } x = x + this.colWidth[c]; if (c == 0) { x = x + this.labelGap; } if (c == 1) { x = x + this.buttonGap; } } } }
From source file:fxts.stations.ui.SideLayout.java
/** * Lays out the grid./*from w ww. ja v a 2 s .co m*/ * * @param aParent the layout container */ protected void arrangeGrid(Container aParent) { ///////////////////////////////////////////////////////// //It`s only for debugging JComponent jc = (JComponent) aParent; String sType = (String) jc.getClientProperty("TYPE"); if (sType != null) { boolean bInternal = "internal".equals(sType); mLogger.debug("\n" + sType); } ////////////////////////////////////////////////////////// Component comp; int compindex; SideConstraints constraints; Insets insets = aParent.getInsets(); Component[] components = aParent.getComponents(); Dimension d; Rectangle r = new Rectangle(); int i, diffw, diffh; double weight; SideLayoutInfo info; mRightToLeft = !aParent.getComponentOrientation().isLeftToRight(); /* * If the parent has no slaves anymore, then don't do anything * at all: just leave the parent's size as-is. */ if (components.length == 0 && (mColumnWidths == null || mColumnWidths.length == 0) && (mRowHeights == null || mRowHeights.length == 0)) { return; } /* * Pass #1: scan all the slaves to figure out the total amount * of space needed. */ info = getLayoutInfo(aParent, PREFERREDSIZE); d = getMinSize(aParent, info); // // System.out.println("parent=w:" + parent.getWidth() + ",h:" + parent.getHeight() + // "min=w:" + d.getWidth() + ",h:" + d.getHeight()); if (aParent.getWidth() < d.width || aParent.getHeight() < d.height) { info = getLayoutInfo(aParent, MINSIZE); d = getMinSize(aParent, info); // // System.out.println("MINSIZE"); } else { // // System.out.println("Non MINSIZE"); } mLayoutInfo = info; r.width = d.width; r.height = d.height; /* * If the current dimensions of the window don't match the desired * dimensions, then adjust the minWidth and minHeight arrays * according to the weights. */ diffw = aParent.getWidth() - r.width; // // System.out.println("diffw=" + diffw); if (diffw != 0) { weight = 0.0; for (i = 0; i < info.width; i++) { weight += info.weightX[i]; } if (weight > 0.0) { for (i = 0; i < info.width; i++) { int dx = (int) (((double) diffw * info.weightX[i]) / weight); info.minWidth[i] += dx; r.width += dx; if (info.minWidth[i] < 0) { r.width -= info.minWidth[i]; info.minWidth[i] = 0; } } } diffw = aParent.getWidth() - r.width; } else { diffw = 0; } diffh = aParent.getHeight() - r.height; // // System.out.println("diffh=" + diffh); if (diffh != 0) { weight = 0.0; for (i = 0; i < info.height; i++) { weight += info.weightY[i]; } if (weight > 0.0) { for (i = 0; i < info.height; i++) { int dy = (int) (((double) diffh * info.weightY[i]) / weight); info.minHeight[i] += dy; r.height += dy; if (info.minHeight[i] < 0) { r.height -= info.minHeight[i]; info.minHeight[i] = 0; } } } diffh = aParent.getHeight() - r.height; } else { diffh = 0; } /* * Now do the actual layout of the slaves using the layout information * that has been collected. */ info.startx = /*diffw/2 +*/ insets.left; info.starty = /*diffh/2 +*/ insets.top; // // System.out.println("info.startx = " + info.startx); // System.out.println("info.starty = " + info.startx); for (compindex = 0; compindex < components.length; compindex++) { comp = components[compindex]; if (!comp.isVisible()) { continue; } constraints = lookupConstraints(comp); if (!mRightToLeft) { r.x = info.startx; for (i = 0; i < constraints.tempX; i++) { r.x += info.minWidth[i]; } } else { r.x = aParent.getWidth() - insets.right; for (i = 0; i < constraints.tempX; i++) { r.x -= info.minWidth[i]; } } r.y = info.starty; for (i = 0; i < constraints.tempY; i++) { r.y += info.minHeight[i]; } r.width = 0; for (i = constraints.tempX; i < constraints.tempX + constraints.tempWidth; i++) { r.width += info.minWidth[i]; } r.height = 0; for (i = constraints.tempY; i < constraints.tempY + constraints.tempHeight; i++) { r.height += info.minHeight[i]; } adjustForGravity(constraints, r); if (r.x < 0) { r.width -= r.x; r.x = 0; } if (r.y < 0) { r.height -= r.y; r.y = 0; } /* * If the window is too small to be interesting then * unmap it. Otherwise configure it and then make sure * it's mapped. */ if (r.width <= 0 || r.height <= 0) { comp.setBounds(0, 0, 0, 0); } else { if (comp.getX() != r.x || comp.getY() != r.y || comp.getWidth() != r.width || comp.getHeight() != r.height) { comp.setBounds(r.x, r.y, r.width, r.height); } } // System.out.println("Initial component size (x = " + (int)comp.getX() + // ", y = " + (int)(comp.getY()) + // ", widht = " + (int)(comp.getWidth()) + // ", height = " + (int)(comp.getHeight())); if (diffw > 0) { // System.out.println("It`s increasing by x!"); //if (comp instanceof IResizableComponent) { // System.out.println("It`s resizable component: " + comp); //IResizableComponent resizeComp = (IResizableComponent)comp; ResizeParameter param = constraints.resize; // System.out.println("Params: Left=" + param.getLeft() + ",top=" + param.getTop() + // ",Right=" + param.getRight() + ",bottom=" + param.getBottom()); comp.setBounds((int) (comp.getX() + diffw * param.getLeft()), comp.getY(), (int) (comp.getWidth() + diffw * (param.getRight() - param.getLeft())), comp.getHeight()); // System.out.println("Set Bounds (x = " + (int)(comp.getX() + diffw * param.getLeft()) + // ", y = " + (int)(comp.getY()) + // ", widht = " + (int)(comp.getWidth() + /// diffw * (param.getRight() - param.getLeft())) + // ", height = " + (int)(comp.getHeight())); // } } if (diffh > 0) { // System.out.println("It`s increasing by y!"); // if (comp instanceof IResizableComponent) { // System.out.println("It`s resizable component: " + comp); // IResizableComponent resizeComp = (IResizableComponent)comp; ResizeParameter param = constraints.resize; // System.out.println("Params: Left=" + param.getLeft() + ",top=" + param.getTop() + // ",Right=" + param.getRight() + ",bottom=" + param.getBottom()); comp.setBounds(comp.getX(), (int) (comp.getY() + diffh * param.getTop()), comp.getWidth(), (int) (comp.getHeight() + diffh * (param.getBottom() - param.getTop()))); // System.out.println("Set Bounds (x = " + (int)(comp.getX()) + // ", y = " + (int)(comp.getY() + diffh * param.getTop()) + // ", widht = " + (int)(comp.getWidth()) + // ", height = " + (int)(comp.getHeight() + // diffh * (param.getBottom() - param.getTop()))); // } } } }
From source file:edu.harvard.i2b2.analysis.ui.ExplorerC.java
public boolean PerformVisualizationQuery(final java.awt.Container oAwtContainer, final int[] patientIds, final boolean bDisplayAll) { bStillPerformingVisualizationQuery = true; bNoError = true;//from w w w.ja v a 2s .c o m p = new WaitPanel((int) (oAwtContainer.getWidth() * 0.40), (int) (oAwtContainer.getHeight() * 0.40), patientIds.length); oAwtContainer.add(p); p.setBounds(0, 0, p.getParent().getWidth(), p.getParent().getHeight()); p.init((int) (p.getParent().getWidth() * 0.40), (int) (p.getParent().getHeight() * 0.40)); p.go(); p.setVisible(true); removelldFile(); visualizationQueryThread = new Thread() { public void run() { log.info("before getResultSetAsi2b2XML: " + new Date()); try { ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel(); String xmlContent = i2b2Model.getContentXml(); oConnection = DBLib.openJDBCConnection(System.getProperty("datamartURL"), System.getProperty("datamartDriver"), System.getProperty("datamartUser"), System.getProperty("datamartPassword")); Properties properties = new Properties(); String writeFileStr = ""; String filename = "crcnavigator.properties"; try { properties.load(new FileInputStream(filename)); writeFileStr = properties.getProperty("writeTimelineFile"); log.debug("Properties writeFile: =" + writeFileStr); } catch (IOException e) { log.error(e.getMessage()); } boolean writeFile = true; if ((writeFileStr != null) && (writeFileStr.equalsIgnoreCase("no"))) { writeFile = false; } String result = DBLib.getResultSetFromI2B2Xml(xmlContent, patientIds, bDisplayAll, oConnection, writeFile, bDisplayDemographics); DBLib.closeConnection(oConnection); if (result != null) { if (result.equalsIgnoreCase("memory error")) { JOptionPane.showMessageDialog(oAwtContainer, "Running out of memory while loading " + patientIds.length + " patients." + "\nPlease try it again with a smaller number of patients."); bNoError = false; } else { PerformMiniVisualization(oAwtContainer, result, writeFile); } } p.stop(); p.setVisible(false); if (result.equalsIgnoreCase("memory error")) { oTheParent.getDisplay().syncExec(new Runnable() { public void run() { tabFolder.setSelection(0); } }); } } catch (Exception e) { log.error(e.getMessage()); bNoError = false; } log.info("after getResultSetAsi2b2XML: " + new Date()); } }; try { visualizationQueryThread.start(); } catch (Exception e) { log.error(e.getMessage()); } return bNoError; }
From source file:edu.harvard.i2b2.analysis.ui.ExplorerC.java
public boolean PerformVisualizationQuery(final java.awt.Container oAwtContainer, final int minPatient, final int maxPatient, final boolean bDisplayAll) { bStillPerformingVisualizationQuery = true; bNoError = true;// w w w.j a v a 2 s .com p = new WaitPanel((int) (oAwtContainer.getWidth() * 0.40), (int) (oAwtContainer.getHeight() * 0.40), (maxPatient - minPatient)); oAwtContainer.add(p); p.setBounds(0, 0, p.getParent().getWidth(), p.getParent().getHeight()); p.init((int) (p.getParent().getWidth() * 0.40), (int) (p.getParent().getHeight() * 0.40)); p.go(); p.setVisible(true); removelldFile(); visualizationQueryThread = new Thread() { public void run() { log.info("before getResultSetAsi2b2XML: " + new Date()); try { ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel(); String xmlContent = i2b2Model.getContentXml(); oConnection = DBLib.openJDBCConnection(System.getProperty("datamartURL"), System.getProperty("datamartDriver"), System.getProperty("datamartUser"), System.getProperty("datamartPassword")); Properties properties = new Properties(); String writeFileStr = ""; String filename = "crcnavigator.properties"; try { properties.load(new FileInputStream(filename)); writeFileStr = properties.getProperty("writeTimelineFile"); log.debug("Properties writeFile: =" + writeFileStr); } catch (IOException e) { log.error(e.getMessage()); } boolean writeFile = false; if ((writeFileStr != null) && (writeFileStr.equalsIgnoreCase("yes"))) { writeFile = true; } String result = DBLib.getResultSetFromI2B2Xml(xmlContent, minPatient, maxPatient, bDisplayAll, oConnection, writeFile, bDisplayDemographics); DBLib.closeConnection(oConnection); if (result != null) { if (result.equalsIgnoreCase("memory error")) { JOptionPane.showMessageDialog(oAwtContainer, "Running out of memory while loading " + (maxPatient - minPatient) + " patients." + "\nPlease try it again with a smaller number of patients."); bNoError = false; } else { PerformMiniVisualization(oAwtContainer, result, writeFile); } } p.stop(); p.setVisible(false); if (result.equalsIgnoreCase("memory error")) { oTheParent.getDisplay().syncExec(new Runnable() { public void run() { tabFolder.setSelection(0); } }); } } catch (Exception e) { p.stop(); p.setVisible(false); oTheParent.getDisplay().syncExec(new Runnable() { public void run() { tabFolder.setSelection(0); } }); log.error(e.getMessage()); bNoError = false; } log.info("after getResultSetAsi2b2XML: " + new Date()); } }; try { visualizationQueryThread.start(); } catch (Exception e) { p.stop(); p.setVisible(false); oTheParent.getDisplay().syncExec(new Runnable() { public void run() { tabFolder.setSelection(0); } }); log.error(e.getMessage()); return false; } return bNoError; }
From source file:edu.harvard.i2b2.analysis.ui.ExplorerC.java
public boolean PerformVisualizationQuery(final java.awt.Container oAwtContainer, final String patientRefId, final int minPatient, final int maxPatient, final boolean bDisplayAll) { bStillPerformingVisualizationQuery = true; bNoError = true;/* w w w.j a v a 2 s . c o m*/ p = new WaitPanel((int) (oAwtContainer.getWidth() * 0.40), (int) (oAwtContainer.getHeight() * 0.40), (maxPatient - minPatient)); oAwtContainer.add(p); p.setBounds(0, 0, p.getParent().getWidth(), p.getParent().getHeight()); p.init((int) (p.getParent().getWidth() * 0.40), (int) (p.getParent().getHeight() * 0.40)); p.go(); p.setVisible(true); removelldFile(); final ExplorerC explorer = this; visualizationQueryThread = new Thread() { public void run() { log.info("before getResultSetAsi2b2XML: " + new Date()); try { ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel(); i2b2Model.fillDataFromTable(rowData); Properties properties = new Properties(); String writeFileStr = ""; String filename = "i2b2workbench.properties"; try { properties.load(new FileInputStream(filename)); writeFileStr = properties.getProperty("writeTimelineFile"); log.debug("Properties writeFile: =" + writeFileStr); } catch (IOException e) { log.error(e.getMessage()); } boolean writeFile = false; if ((writeFileStr != null) && (writeFileStr.equalsIgnoreCase("yes"))) { writeFile = true; } ArrayList<TimelineRow> tlrows = i2b2Model.getTimelineRows(rowData); String result = CRCQueryClient.getlldString(tlrows, patientRefId, minPatient, minPatient + maxPatient, bDisplayAll, writeFile, bDisplayDemographics, explorer); if (result != null) { if (result.equalsIgnoreCase("memory error")) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(oAwtContainer, "Running out of memory while loading " + (maxPatient - minPatient) + " patients." + "\nPlease try it again with a smaller number of patients."); } }); bNoError = false; } else if (result.equalsIgnoreCase("error")) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(oAwtContainer, "Response delivered from the remote server could not be " + "understood, you may wish to retry your last action"); } }); bNoError = false; } else { PerformMiniVisualization(oAwtContainer, result, writeFile); } } else { // JOptionPane.showMessageDialog(oAwtContainer, // "Response delivered from the remote server could not be understood, you may wish to retry your last action" // ); bNoError = false; } p.stop(); p.setVisible(false); if (result == null || result.equalsIgnoreCase("memory error") || result.equalsIgnoreCase("error")) { oTheParent.getDisplay().syncExec(new Runnable() { public void run() { tabFolder.setSelection(0); } }); } } catch (Exception e) { log.error(e.getMessage()); bNoError = false; } log.info("after getResultSetAsi2b2XML: " + new Date()); } }; try { visualizationQueryThread.start(); } catch (Exception e) { log.error(e.getMessage()); } return bNoError; }
From source file:edu.harvard.i2b2.patientMapping.ui.MainComposite.java
public boolean PerformVisualizationQuery(final java.awt.Container oAwtContainer, final String patientRefId, final int minPatient, final int maxPatient, final boolean bDisplayAll) { bStillPerformingVisualizationQuery = true; bNoError = true;//from w ww .j a v a2 s. c o m p = new WaitPanel((int) (oAwtContainer.getWidth() * 0.40), (int) (oAwtContainer.getHeight() * 0.40), (maxPatient - minPatient)); oAwtContainer.add(p); p.setBounds(0, 0, p.getParent().getWidth(), p.getParent().getHeight()); p.init((int) (p.getParent().getWidth() * 0.40), (int) (p.getParent().getHeight() * 0.40)); p.go(); p.setVisible(true); removelldFile(); final MainComposite explorer = this; visualizationQueryThread = new Thread() { public void run() { log.info("before getResultSetAsi2b2XML: " + new Date()); try { ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel(); i2b2Model.fillDataFromTable(rowData); Properties properties = new Properties(); String writeFileStr = ""; String filename = "i2b2workbench.properties"; try { properties.load(new FileInputStream(filename)); writeFileStr = properties.getProperty("writeTimelineFile"); log.debug("Properties writeFile: =" + writeFileStr); } catch (IOException e) { log.error(e.getMessage()); } boolean writeFile = false; if ((writeFileStr != null) && (writeFileStr.equalsIgnoreCase("yes"))) { writeFile = true; } ArrayList<TimelineRow> tlrows = i2b2Model.getTimelineRows(rowData); String result = PatientMappingQueryClient.getlldString(tlrows, patientRefId, minPatient, minPatient + maxPatient, bDisplayAll, writeFile, bDisplayDemographics, explorer); if (result != null) { if (result.equalsIgnoreCase("memory error")) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(oAwtContainer, "Running out of memory while loading " + (maxPatient - minPatient) + " patients." + "\nPlease try it again with a smaller number of patients."); } }); bNoError = false; } else if (result.equalsIgnoreCase("error")) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(oAwtContainer, "Response delivered from the remote server could not be " + "understood, you may wish to retry your last action"); } }); bNoError = false; } else { PerformMiniVisualization(oAwtContainer, result, writeFile); } } else { // JOptionPane.showMessageDialog(oAwtContainer, // "Response delivered from the remote server could not be understood, you may wish to retry your last action" // ); bNoError = false; } p.stop(); p.setVisible(false); if (result == null || result.equalsIgnoreCase("memory error") || result.equalsIgnoreCase("error")) { oTheParent.getDisplay().syncExec(new Runnable() { public void run() { tabFolder.setSelection(0); } }); } } catch (Exception e) { log.error(e.getMessage()); bNoError = false; e.printStackTrace(); } log.info("after getResultSetAsi2b2XML: " + new Date()); } }; try { visualizationQueryThread.start(); } catch (Exception e) { log.error(e.getMessage()); } return bNoError; }
From source file:edu.harvard.i2b2.explorer.ui.MainComposite.java
public boolean PerformVisualizationQuery(final java.awt.Container oAwtContainer, final String patientRefId, final int minPatient, final int maxPatient, final boolean bDisplayAll) { bStillPerformingVisualizationQuery = true; bNoError = true;/*from w w w . j a v a 2s . com*/ p = new WaitPanel((int) (oAwtContainer.getWidth() * 0.40), (int) (oAwtContainer.getHeight() * 0.40), (maxPatient - minPatient)); oAwtContainer.add(p); p.setBounds(0, 0, p.getParent().getWidth(), p.getParent().getHeight()); p.init((int) (p.getParent().getWidth() * 0.40), (int) (p.getParent().getHeight() * 0.40)); p.go(); p.setVisible(true); removelldFile(); final MainComposite explorer = this; visualizationQueryThread = new Thread() { public void run() { log.info("before getResultSetAsi2b2XML: " + new Date()); try { ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel(); i2b2Model.fillDataFromTable(rowData); Properties properties = new Properties(); String writeFileStr = ""; String filename = "i2b2workbench.properties"; try { properties.load(new FileInputStream(filename)); writeFileStr = properties.getProperty("writeTimelineFile"); log.debug("Properties writeFile: =" + writeFileStr); } catch (IOException e) { log.error(e.getMessage()); } boolean writeFile = false; if ((writeFileStr != null) && (writeFileStr.equalsIgnoreCase("yes"))) { writeFile = true; } ArrayList<TimelineRow> tlrows = i2b2Model.getTimelineRows(rowData); String result = PDOQueryClient.getlldString(tlrows, patientRefId, minPatient, minPatient + maxPatient, bDisplayAll, writeFile, bDisplayDemographics, explorer, filter); if (result != null) { if (result.equalsIgnoreCase("memory error")) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(oAwtContainer, "Running out of memory while loading " + (maxPatient - minPatient) + " patients." + "\nPlease try it again with a smaller number of patients."); } }); bNoError = false; } else if (result.equalsIgnoreCase("error")) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(oAwtContainer, "Response delivered from the remote server could not be " + "understood, you may wish to retry your last action"); } }); bNoError = false; } else { PerformMiniVisualization(oAwtContainer, result, writeFile); } } else { // JOptionPane.showMessageDialog(oAwtContainer, // "Response delivered from the remote server could not be understood, you may wish to retry your last action" // ); bNoError = false; } p.stop(); p.setVisible(false); if (result == null || result.equalsIgnoreCase("memory error") || result.equalsIgnoreCase("error")) { oTheParent.getDisplay().syncExec(new Runnable() { public void run() { tabFolder.setSelection(0); } }); } } catch (Exception e) { log.error(e.getMessage()); bNoError = false; e.printStackTrace(); } log.info("after getResultSetAsi2b2XML: " + new Date()); } }; try { visualizationQueryThread.start(); } catch (Exception e) { log.error(e.getMessage()); } return bNoError; }
From source file:org.jcurl.demo.tactics.JCurlShotPlanner.java
private static void renderPng(final Container src, final File dst) throws IOException { final BufferedImage img = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics g = img.getGraphics(); try {/*from ww w .j a v a2s .co m*/ // SwingUtilities.paintComponent(g, src, src.getBounds(), null); src.paintAll(g); } finally { g.dispose(); } ImageIO.write(img, "png", dst); }
From source file:phex.gui.common.FileDialogHandler.java
/** * @param chooser//from w ww .jav a 2 s.c om */ private static void displayNotificationPopup(JComponent chooser, String title, String shortMessage) { final SlideInWindow window = new SlideInWindow(title, 0); window.setShortMessage(shortMessage, true); window.setHideBtnShown(false); window.initializeComponent(); window.setSize(200, 150); chooser.addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { window.setVisible(true); } public void ancestorRemoved(AncestorEvent event) { window.setVisible(false); } public void ancestorMoved(AncestorEvent event) { Container ancestor = event.getAncestor(); Point loc = ancestor.getLocationOnScreen(); int xPos = loc.x + ancestor.getWidth() + 5; int yPos = loc.y + ancestor.getHeight() - window.getHeight(); window.setLocation(xPos, yPos); } }); }