Java Code Examples for javax.swing.JWindow#setSize()

The following examples show how to use javax.swing.JWindow#setSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MesquiteFileDialog.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
public MesquiteFileDialog (MesquiteWindow f, String message, int type) {
	super(getFrame(f), message, type);
	if (type == FileDialog.LOAD &&  (MesquiteTrunk.isMacOS() || MesquiteTrunk.isMacOSX()) && MesquiteTrunk.getOSXVersion()>10){
		titleWindow = new JWindow(); 
		titleWindow.setSize(twWidth,twHeight);
		titleWindowLabel = new Label();
		titleWindowLabel.setBackground(ColorDistribution.veryLightYellow); //ColorTheme.getExtInterfaceBackground()); //ColorDistribution.veryLightGray
		titleWindow.add(titleWindowLabel);
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		int v, h;
		h = (screenSize.width-twWidth)/2;
		v = 26;
		titleWindow.setLocation(h, v);
		titleWindowLabel.setText("  " + message);
	//	Color darkBlue = new Color((float)0.0, (float)0.0, (float)0.7);
		titleWindowLabel.setForeground(ColorDistribution.darkBlue); //ColorTheme.getExtInterfaceElement(true));

	}
	this.message = message;
	this.type = type;
	currentFileDialog = this;
	//mfdThread = new MFDThread(this);
	//mfdThread.start();
	MainThread.incrementSuppressWaitWindow();
}
 
Example 2
Source File: GrabOnUnfocusableToplevel.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 3
Source File: RoarPanel.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the WindowGui
 * 
 * @param icon
 * @param head
 * @param body
 * @param posx
 * @param posy
 * @param backgroundcolor
 * @param headerColor
 * @param messageColor
 * @return
 */
private static JWindow createWindow(Icon icon, String head, String body, int posx, int posy, Color backgroundcolor,
        Color headerColor, Color messageColor) {

    final JWindow window = new JWindow();
    JPanel windowpanel = new JPanel(new GridBagLayout());
    windowpanel.setBackground(backgroundcolor);

    AWTUtilities.setWindowShape(window, new RoundRectangle2D.Float(0, 0, WIDTH, HEIGHT, 20, 20));

    try
    {
        AWTUtilities.setWindowOpaque( window, true );
    } catch ( UnsupportedOperationException ex ) {
        Log.debug( "Unable to make window opaque: " + ex );
    }
    JLabel text = new JLabel("<HTML>" + body + "</HTML>");
    text.setForeground(messageColor);

    JLabel header = new JLabel(head);
    header.setForeground(headerColor);
    header.setFont(new Font(header.getFont().getName(), Font.BOLD, header.getFont().getSize() + 2));

    windowpanel.add(new JLabel(icon), new GridBagConstraints(0, 0, 1, 2, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));

    windowpanel.add(header, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(5, 5, 0, 5), 0, 0));
    windowpanel.add(text, new GridBagConstraints(1, 1, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 5), 0, 0));

    window.add(windowpanel);
    window.setSize(WIDTH, HEIGHT);
    window.setLocation(posx - (WIDTH + 5), posy + 5);
    window.setAlwaysOnTop(true);

    return window;
}
 
Example 4
Source File: AbstractSliderTool.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
private void initializeSlider(TopicMapGraphPanel gp) {
    int minValue = getMinValue(gp);
    int maxValue = getMaxValue(gp);
    int defaultValue = getDefaultValue(gp);
    
    if(defaultValue < minValue) defaultValue = minValue;
    if(defaultValue > maxValue) defaultValue = maxValue;

    slider = new SimpleSlider(SimpleSlider.HORIZONTAL, minValue, maxValue, defaultValue);
    sliderLabel = new SimpleLabel();
    sliderPopup = new JWindow();

    slider.setPreferredSize(new Dimension(120, 24));
    slider.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    
    sliderLabel.setFont(UIConstants.smallButtonLabelFont);
    sliderLabel.setPreferredSize(new Dimension(30, 24));
    sliderLabel.setHorizontalAlignment(SimpleLabel.CENTER);
    
    JPanel panel = new JPanel();
    panel.setBorder(new LineBorder(UIConstants.defaultBorderShadow));
    panel.setLayout(new BorderLayout(2,2));
    panel.add(slider, BorderLayout.CENTER);
    panel.add(sliderLabel, BorderLayout.EAST);

    sliderPopup.setLayout(new BorderLayout(2,2));
    sliderPopup.add(panel, BorderLayout.CENTER);
    sliderPopup.setSize(150, 24);

    // sliderPopup.addMouseListener(this);
    sliderPopup.setAlwaysOnTop(true);
    
    slider.addChangeListener(this);
    slider.addMouseListener(this);
}
 
Example 5
Source File: GrabOnUnfocusableToplevel.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 6
Source File: GrabOnUnfocusableToplevel.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 7
Source File: GrabOnUnfocusableToplevel.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 8
Source File: GrabOnUnfocusableToplevel.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 9
Source File: GrabOnUnfocusableToplevel.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 10
Source File: GrabOnUnfocusableToplevel.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 11
Source File: GrabOnUnfocusableToplevel.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 12
Source File: GrabOnUnfocusableToplevel.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 13
Source File: GrabOnUnfocusableToplevel.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 14
Source File: TooltipWindow.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void show(Point location) {
    Rectangle screenBounds = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    for (GraphicsDevice device : gds) {
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        screenBounds = gc.getBounds();
        if (screenBounds.contains(location)) {
            break;
        }
    }

    // showing the popup tooltip
    cp = new TooltipContentPanel(master.getTextComponent());

    Window w = SwingUtilities.windowForComponent(master.getTextComponent());
    contentWindow = new JWindow(w);
    contentWindow.add(cp);
    contentWindow.pack();
    Dimension dim = contentWindow.getSize();

    if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) {
        dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER);
    }
    if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) {
        dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER);
    }

    contentWindow.setSize(dim);

    contentWindow.setLocation(location.x, location.y - 1);  // slight visual adjustment
    contentWindow.setVisible(true);

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
    w.addWindowFocusListener(this);
    contentWindow.addWindowFocusListener(this);
}
 
Example 15
Source File: TooltipWindow.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void show(Point location) {
    Rectangle screenBounds = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    for (GraphicsDevice device : gds) {
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        screenBounds = gc.getBounds();
        if (screenBounds.contains(location)) {
            break;
        }
    }

    // showing the popup tooltip
    cp = new TooltipContentPanel(master.getTextComponent());
    Window w = SwingUtilities.windowForComponent(master.getTextComponent());
    contentWindow = new JWindow(w);
    contentWindow.add(cp);
    contentWindow.pack();
    Dimension dim = contentWindow.getSize();

    if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) {
        dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER);
    }
    if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) {
        dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER);
    }

    contentWindow.setSize(dim);

    contentWindow.setLocation(location.x, location.y - 1);  // slight visual adjustment
    contentWindow.setVisible(true);
    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
    w.addWindowFocusListener(this);
    contentWindow.addWindowFocusListener(this);
}
 
Example 16
Source File: TooltipWindow.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void show(Point location) {
    Rectangle screenBounds = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    for (GraphicsDevice device : gds) {
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        screenBounds = gc.getBounds();
        if (screenBounds.contains(location)) {
            break;
        }
    }

    // showing the popup tooltip
    cp = new TooltipContentPanel(master.getTextComponent());

    Window w = SwingUtilities.windowForComponent(master.getTextComponent());
    contentWindow = new JWindow(w);
    contentWindow.add(cp);
    contentWindow.pack();
    Dimension dim = contentWindow.getSize();

    if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) {
        dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER);
    }
    if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) {
        dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER);
    }

    contentWindow.setSize(dim);

    contentWindow.setLocation(location.x, location.y - 1);  // slight visual adjustment
    contentWindow.setVisible(true);

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
    w.addWindowFocusListener(this);
    contentWindow.addWindowFocusListener(this);
}
 
Example 17
Source File: GrabOnUnfocusableToplevel.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 18
Source File: GrabOnUnfocusableToplevel.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 19
Source File: GrabOnUnfocusableToplevel.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example 20
Source File: MsgTooltipWindow.java    From netbeans with Apache License 2.0 4 votes vote down vote up
void show(Point location) {
    Rectangle screenBounds = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    for (GraphicsDevice device : gds) {
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        screenBounds = gc.getBounds();
        if (screenBounds.contains(location)) {
            break;
        }
    }

    // showing the popup tooltip
    cp = new TooltipContentPanel();
    Window w = SwingUtilities.windowForComponent(parent);
    contentWindow = new JWindow(w);
    contentWindow.add(cp);
    contentWindow.pack();
    Dimension dim = contentWindow.getSize();

    if (screenBounds.width + screenBounds.x - location.x < cp.longestLine) {
        // the whole window does fully not fit to the right
        // the x position where the window has to start to fully fit to the right
        int left = screenBounds.width + screenBounds.x - cp.longestLine;
        // the window should have x pos minimally at the screen's start
        location.x = Math.max(screenBounds.x, left);
    }
    
    if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) {
        dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER);
    }
    if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) {
        dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER);
    }

    contentWindow.setSize(dim);

    contentWindow.setLocation(location.x, location.y + 1);  // slight visual adjustment
    
    contentWindow.setVisible(true);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            cp.scrollRectToVisible(new Rectangle(1, 1));
        }
    });
    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
    w.addWindowFocusListener(this);
    contentWindow.addWindowFocusListener(this);
    contentWindow.addKeyListener(this);
    w.addKeyListener(this);
}