Java Code Examples for java.awt.Window#setVisible()

The following examples show how to use java.awt.Window#setVisible() . 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: BackgroundIsNotUpdated.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) throws AWTException {
    final Window window = new BackgroundIsNotUpdated(null);
    window.setSize(300, 300);
    window.setLocationRelativeTo(null);
    window.setVisible(true);
    window.requestFocus();
    final ExtendedRobot robot = new ExtendedRobot();
    robot.setAutoDelay(200);
    robot.waitForIdle(1000);
    window.setBackground(Color.GREEN);
    robot.waitForIdle(1000);
    Point point = window.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
                                      point.y + window.getHeight() / 2);
    window.dispose();
    if (!color.equals(Color.GREEN)) {
        throw new RuntimeException(
                "Expected: " + Color.GREEN + " , Actual: " + color);
    }
}
 
Example 2
Source File: Util.java    From beanshell with Apache License 2.0 6 votes vote down vote up
public static void startSplashScreen()
{
    int width=275,height=148;
    Window win=new Window( new Frame() );
    win.pack();
    BshCanvas can=new BshCanvas();
    can.setSize( width, height ); // why is this necessary?
    Toolkit tk=Toolkit.getDefaultToolkit();
    Dimension dim=tk.getScreenSize();
    win.setBounds(
        dim.width/2-width/2, dim.height/2-height/2, width, height );
    win.add("Center", can);
    Image img=tk.getImage(
        Interpreter.class.getResource("/bsh/util/lib/splash.gif") );
    MediaTracker mt=new MediaTracker(can);
    mt.addImage(img,0);
    try { mt.waitForAll(); } catch ( Exception e ) { }
    Graphics gr=can.getBufferedGraphics();
    gr.drawImage(img, 0, 0, can);
    win.setVisible(true);
    win.toFront();
    splashScreen = win;
}
 
Example 3
Source File: MnemonicSearchPluginTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that when multiple regions are selected, the user is notified via
 * pop-up that this is not acceptable.
 * 
 */
@Test
public void testMultipleSelection() {

	// First set up two selection ranges.
	AddressRange range1 = new AddressRangeImpl(addr(0x01004062), addr(0x01004064));
	AddressRange range2 = new AddressRangeImpl(addr(0x0100406c), addr(0x0100406e));
	AddressSet addrSet = new AddressSet();
	addrSet.add(range1);
	addrSet.add(range2);

	// Create an event that we can fire to all subscribers, and send it.
	makeSelection(tool, program, addrSet);

	// Now invoke the menu option we want to test.
	performAction(searchMnemonicOperandsConstAction, cb.getProvider(), false);

	// Here's the main assert: If the code recognizes that we have multiple selection, the 
	// MemSearchDialog will NOT be displayed (an error message pops up instead).  So verify that
	// the dialog is null and we're ok.
	Window errorDialog = waitForWindow("Mnemonic Search Error", 2000);
	assertNotNull(errorDialog);
	errorDialog.setVisible(false);
}
 
Example 4
Source File: BackgroundIsNotUpdated.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) throws AWTException {
    final Window window = new BackgroundIsNotUpdated(null);
    window.setSize(300, 300);
    window.setLocationRelativeTo(null);
    window.setVisible(true);
    sleep();
    window.setBackground(Color.GREEN);
    sleep();
    final Robot robot = new Robot();
    robot.setAutoDelay(200);
    Point point = window.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
                                      point.y + window.getHeight() / 2);
    window.dispose();
    if (!color.equals(Color.GREEN)) {
        throw new RuntimeException(
                "Expected: " + Color.GREEN + " , Actual: " + color);
    }
}
 
Example 5
Source File: PageableTable.java    From jdal with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
	Point point = e.getPoint();
	int row = table.rowAtPoint(point);
	int col = table.columnAtPoint(point);
	// check Actions
	if (col != -1 && row != -1 && tableModel.isActionColumn(col)) {
		TableRowAction action = (TableRowAction) tableModel.getValueAt(row, col);
		action.setTable(PageableTable.this);
		action.setRow(tableModel.getList().get(row));
		action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "clicked"));
		
	}
	// check double click on rows
	if (row != -1 && e.getClickCount() == 2) {
		Object toEdit = tableModel.getList().get(row);
		Window dlg = getEditor(toEdit);
		if (dlg != null) {
			if (dlg instanceof Frame) {
				((Frame) dlg).setState(Frame.NORMAL);
				((Frame) dlg).requestFocus();
			}
			dlg.setLocationRelativeTo(null);
			dlg.setVisible(true);
		}
	}
}
 
Example 6
Source File: LocationByPlatformTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {

        Window window = new Window(null);
        window.setSize(100, 100);
        window.setLocationByPlatform(true);

        if (!window.isLocationByPlatform()) {
            throw new RuntimeException("Location by platform is not set");
        }

        window.setLocation(10, 10);

        if (window.isLocationByPlatform()) {
            throw new RuntimeException("Location by platform is not cleared");
        }

        window.setLocationByPlatform(true);
        window.setBounds(20, 20, 50, 50);

        if (window.isLocationByPlatform()) {
            throw new RuntimeException("Location by platform is not cleared");
        }

        window.setLocationByPlatform(true);
        window.setVisible(false);

        if (window.isLocationByPlatform()) {
            throw new RuntimeException("Location by platform is not cleared");
        }

        window.setLocationByPlatform(true);
        window.setVisible(true);

        if (window.isLocationByPlatform()) {
            throw new RuntimeException("Location by platform is not cleared");
        }

        window.dispose();
    }
 
Example 7
Source File: RootPm.java    From pgptool with GNU General Public License v3.0 5 votes vote down vote up
protected void openWindow(ActionEvent originAction) {
	Window optionalOrigin = UiUtils.findWindow(originAction);

	if (pm != null && view != null && view instanceof HasWindow) {
		log.debug("Window is already opened -- just bring it to top " + view);
		Window window = ((HasWindow) view).getWindow();
		// TODO: Move this code to same place where we do center window
		UiUtils.centerWindow(window, optionalOrigin);
		window.setVisible(true);
		return;
	}

	if (pm == null) {
		pm = applicationContext.getBean(pmClass);
		if (!initPm(originAction)) {
			pm.detach();
			pm = null;
			return;
		}
	}

	if (view == null) {
		buildViewInstance();
	}
	view.setPm(pm);
	doRenderView(optionalOrigin);
}
 
Example 8
Source File: ShowRowAction.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
	Window dlg = getTable().getEditor(getRow());
	if (dlg != null) {
		if (dlg instanceof Frame) {
			((Frame) dlg).setState(Frame.NORMAL);
			((Frame) dlg).requestFocus();
		}
		dlg.setLocationRelativeTo(null);
		dlg.setAlwaysOnTop(true);
		dlg.setVisible(true);
	}
}
 
Example 9
Source File: PreviewPane.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void closeToolbar() {
  if ( toolBar == null ) {
    return;
  }
  if ( toolBar.getParent() != toolbarHolder ) {
    // ha!, we detected that the toolbar is floating ...
    // Log.debug (currentToolbar.getParent());
    final Window w = SwingUtilities.windowForComponent( toolBar );
    if ( w != null ) {
      w.setVisible( false );
      w.dispose();
    }
  }
  toolBar.setVisible( false );
}
 
Example 10
Source File: ResizablePopup.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void cleanup(Window window) {
    window.setVisible(false);
    if (window instanceof RootPaneContainer) {
        ((RootPaneContainer) window).setContentPane(new JPanel());
    }
    window.removeWindowListener(this);
    window.dispose();
}
 
Example 11
Source File: ControlWindow.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
public void show() {
  // ((Window) getComponent()).show();
  if(startingup) {
    shouldShow = true;
    if(waitForReset) {
      return;
    }
  }
  Window w = (Window) getComponent();
  if(w.isShowing()) {
    // empty  // System.out.println("Window "+this+" is showing "+w.isShowing());
  } else {
    w.setVisible(true);
  }
}
 
Example 12
Source File: Test4759934.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void show(Window window, String command) {
    JButton button = new JButton(command);
    button.setActionCommand(command);
    button.addActionListener(this);
    button.setFont(button.getFont().deriveFont(64.0f));

    window.add(button);
    window.pack();
    window.setVisible(true);
}
 
Example 13
Source File: LocationByPlatformTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {

        Window window = new Window(null);
        window.setSize(100, 100);
        window.setLocationByPlatform(true);

        if (!window.isLocationByPlatform()) {
            throw new RuntimeException("Location by platform is not set");
        }

        window.setLocation(10, 10);

        if (window.isLocationByPlatform()) {
            throw new RuntimeException("Location by platform is not cleared");
        }

        window.setLocationByPlatform(true);
        window.setBounds(20, 20, 50, 50);

        if (window.isLocationByPlatform()) {
            throw new RuntimeException("Location by platform is not cleared");
        }

        window.setLocationByPlatform(true);
        window.setVisible(false);

        if (window.isLocationByPlatform()) {
            throw new RuntimeException("Location by platform is not cleared");
        }

        window.setLocationByPlatform(true);
        window.setVisible(true);

        if (window.isLocationByPlatform()) {
            throw new RuntimeException("Location by platform is not cleared");
        }

        window.dispose();
    }
 
Example 14
Source File: FullScreenInsets.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    final GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    final GraphicsDevice[] devices = ge.getScreenDevices();

    final Window wGreen = new Frame();
    wGreen.setBackground(Color.GREEN);
    wGreen.setSize(300, 300);
    wGreen.setVisible(true);
    sleep();
    final Insets iGreen = wGreen.getInsets();
    final Dimension sGreen = wGreen.getSize();

    final Window wRed = new Frame();
    wRed.setBackground(Color.RED);
    wRed.setSize(300, 300);
    wRed.setVisible(true);
    sleep();
    final Insets iRed = wGreen.getInsets();
    final Dimension sRed = wGreen.getSize();

    for (final GraphicsDevice device : devices) {
        if (!device.isFullScreenSupported()) {
            continue;
        }
        device.setFullScreenWindow(wGreen);
        sleep();
        testWindowBounds(device.getDisplayMode(), wGreen);
        testColor(wGreen, Color.GREEN);

        device.setFullScreenWindow(wRed);
        sleep();
        testWindowBounds(device.getDisplayMode(), wRed);
        testColor(wRed, Color.RED);

        device.setFullScreenWindow(null);
        sleep();
        testInsets(wGreen.getInsets(), iGreen);
        testInsets(wRed.getInsets(), iRed);
        testSize(wGreen.getSize(), sGreen);
        testSize(wRed.getSize(), sRed);
    }
    wGreen.dispose();
    wRed.dispose();
    if (!passed) {
        throw new RuntimeException("Test failed");
    }
}
 
Example 15
Source File: FullScreenInsets.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    final GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    final GraphicsDevice[] devices = ge.getScreenDevices();

    final Window wGreen = new Frame();
    wGreen.setBackground(Color.GREEN);
    wGreen.setSize(300, 300);
    wGreen.setVisible(true);
    sleep();
    final Insets iGreen = wGreen.getInsets();
    final Dimension sGreen = wGreen.getSize();

    final Window wRed = new Frame();
    wRed.setBackground(Color.RED);
    wRed.setSize(300, 300);
    wRed.setVisible(true);
    sleep();
    final Insets iRed = wGreen.getInsets();
    final Dimension sRed = wGreen.getSize();

    for (final GraphicsDevice device : devices) {
        if (!device.isFullScreenSupported()) {
            continue;
        }
        device.setFullScreenWindow(wGreen);
        sleep();
        testWindowBounds(device.getDisplayMode(), wGreen);
        testColor(wGreen, Color.GREEN);

        device.setFullScreenWindow(wRed);
        sleep();
        testWindowBounds(device.getDisplayMode(), wRed);
        testColor(wRed, Color.RED);

        device.setFullScreenWindow(null);
        sleep();
        testInsets(wGreen.getInsets(), iGreen);
        testInsets(wRed.getInsets(), iRed);
        testSize(wGreen.getSize(), sGreen);
        testSize(wRed.getSize(), sRed);
    }
    wGreen.dispose();
    wRed.dispose();
    if (!passed) {
        throw new RuntimeException("Test failed");
    }
}
 
Example 16
Source File: ExportDialog.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void showExportDialog(PCGenFrame parent)
{
	Window dialog = new ExportDialog(parent);
	dialog.setLocationRelativeTo(parent);
	dialog.setVisible(true);
}
 
Example 17
Source File: FullScreenInsets.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    final GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    final GraphicsDevice[] devices = ge.getScreenDevices();

    final Window wGreen = new Frame();
    wGreen.setBackground(Color.GREEN);
    wGreen.setSize(300, 300);
    wGreen.setVisible(true);
    sleep();
    final Insets iGreen = wGreen.getInsets();
    final Dimension sGreen = wGreen.getSize();

    final Window wRed = new Frame();
    wRed.setBackground(Color.RED);
    wRed.setSize(300, 300);
    wRed.setVisible(true);
    sleep();
    final Insets iRed = wGreen.getInsets();
    final Dimension sRed = wGreen.getSize();

    for (final GraphicsDevice device : devices) {
        if (!device.isFullScreenSupported()) {
            continue;
        }
        device.setFullScreenWindow(wGreen);
        sleep();
        testWindowBounds(device.getDisplayMode(), wGreen);
        testColor(wGreen, Color.GREEN);

        device.setFullScreenWindow(wRed);
        sleep();
        testWindowBounds(device.getDisplayMode(), wRed);
        testColor(wRed, Color.RED);

        device.setFullScreenWindow(null);
        sleep();
        testInsets(wGreen.getInsets(), iGreen);
        testInsets(wRed.getInsets(), iRed);
        testSize(wGreen.getSize(), sGreen);
        testSize(wRed.getSize(), sRed);
    }
    wGreen.dispose();
    wRed.dispose();
    if (!passed) {
        throw new RuntimeException("Test failed");
    }
}
 
Example 18
Source File: DialogDisplayerImplTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@RandomlyFails
public void testLeafNotify() throws Exception {
    boolean leaf = true;
    DialogDescriptor ownerDD = new DialogDescriptor (pane, "Owner", true, new Object[] {closeOwner}, null, 0, null, null, leaf);
    final Dialog owner = DialogDisplayer.getDefault ().createDialog (ownerDD);
    
    // make leaf visible
    postInAwtAndWaitOutsideAwt (new Runnable () {
        @Override
        public void run () {
            owner.setVisible (true);
        }
    });
    assertShowing("Owner should be visible", true, owner);
    
    child = new JButton();
    final NotifyDescriptor nd = new NotifyDescriptor.Message(child);

    // make the child visible
    RequestProcessor.getDefault().post(new Runnable () {
        @Override
        public void run () {
            DialogDisplayer.getDefault().notify(nd);
        }
    });
    assertShowing("Child will be visible", true, child);
    
    Window w = SwingUtilities.windowForComponent(child);
    assertFalse ("No dialog is owned by leaf dialog.", owner.equals (w.getOwner ()));
    assertEquals ("The leaf dialog has no child.", 0, owner.getOwnedWindows ().length);
    
    assertTrue ("Leaf is visible", owner.isVisible ());
    assertTrue ("Child is visible", child.isVisible ());
    
    // close the leaf window
    postInAwtAndWaitOutsideAwt (new Runnable () {
        @Override
        public void run () {
            owner.setVisible (false);
        }
    });
    assertShowing("Disappear", false, owner);
    
    assertFalse ("Leaf is dead", owner.isVisible ());
    assertTrue ("Child is visible still", child.isVisible ());

    w.setVisible(false);
    assertShowing("Child is invisible", false, child);
    
    assertFalse ("Child is dead too", child.isShowing());
}
 
Example 19
Source File: WindowOwnedByEmbeddedFrameTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    try {
        Robot robot = Util.createRobot();
        robot.setAutoDelay(50);

        embeddedFrame = createEmbeddedFrame();

        textField = new TextField("");

        window = new Window(embeddedFrame);
        window.setSize(200, 200);
        window.setLocationRelativeTo(null);
        window.add(textField);
        window.setVisible(true);

        Util.waitForIdle(robot);

        Util.clickOnComp(textField, robot);
        Util.waitForIdle(robot);

        robot.keyPress(KeyEvent.VK_T);
        robot.keyRelease(KeyEvent.VK_T);
        Util.waitForIdle(robot);

        robot.keyPress(KeyEvent.VK_E);
        robot.keyRelease(KeyEvent.VK_E);
        Util.waitForIdle(robot);

        robot.keyPress(KeyEvent.VK_S);
        robot.keyRelease(KeyEvent.VK_S);
        Util.waitForIdle(robot);

        robot.keyPress(KeyEvent.VK_T);
        robot.keyRelease(KeyEvent.VK_T);
        Util.waitForIdle(robot);

        if ("".equals(textField.getText())) {
            throw new RuntimeException("Keyboard input in text field isn't possible");
        }
    } finally {
        if (embeddedFrame != null) {
            embeddedFrame.dispose();
        }
        if (window != null) {
            window.dispose();
        }
    }
}
 
Example 20
Source File: SyncAlwaysOnTopFieldTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static Window createWindow(Window parent) {
    Window window = new Window(parent);
    window.setSize(200, 200);
    window.setVisible(true);
    return window;
}