Results 1 to 2 of 2
  1. #1
    rru96 is offline Senior Member
    Join Date
    Sep 2012
    Posts
    108
    Rep Power
    0

    Default Hiding primaryStage still shows up

    The problem is that I am trying to capture a screenshot, but according to my program, the stage is still being displayed (though oddly enough, it still goes through the hiding action). So in essence, it hides, but mysteriously still shows itself in the capture.

    In my Main application file, I have the following:
    Java FX Code:
    private static Stage primaryStage;
    and the following 2 methods I added in:
    Java FX Code:
    public static void hideStage(){
    		primaryStage.hide();
    	}
    	
    	public static void showStage(){
    		primaryStage.show();
    	}
    In my MainController file I have a button that has ab ActionEvent tied to it. OnHandle, this button is supposed to do the following:
    Hide Application window
    Capture Screenshot
    Show Application window
    Display Screenshot in specified ImageView



    This is the handle action for my capture button
    Java FX Code:
    public void handle(ActionEvent event) {
    				Robot robot;
    				try {
    					Main.hideStage();
    					robot = new Robot();
    					BufferedImage screenCap = robot.createScreenCapture(new java.awt.Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
    					Image shot = SwingFXUtils.toFXImage(screenCap, null);
    					screenImage.setImage(shot);
    					Main.showStage();
    				} catch (AWTException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    				
    			}
    Is there an issue with me using an awt robot, or is there something I am missing ?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Hiding primaryStage still shows up

    Looks like a concurrency issue to me. I would try wrapping lines 5 through 9 in a Platform.runLater(...) and within that, wrap line 9 in an EventQueue.invokeLater(...), with further nested calls to run each UI kit on its appropriate thread. Something like (typed here, may have typos or other bloopers)
    Java FX Code:
    public void handle(ActionEvent event) {
      Robot robot;
      Main.hideStage();
      Platform.runLater(() -> EventQueue.invokeLater(() -> {
        try {
          robot = new Robot();
          BufferedImage screenCap = robot.createScreenCapture(new java.awt.Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
          Image shot = SwingFXUtils.toFXImage(screenCap, null);
          Platform.runLater(() -> screenImage.setImage(shot));
        } catch (AWTException e) {
          e.printStackTrace();
        }
        Platform.runLater(() -> Main.showStage());
      }));
    }
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Inheritance......nothing shows up
    By RBDiaz31 in forum New To Java
    Replies: 7
    Last Post: 08-05-2013, 08:05 AM
  2. Menu Bar hiding behind PDF in IE9
    By kraonasu in forum New To Java
    Replies: 3
    Last Post: 06-08-2011, 04:56 AM
  3. JPopupMenu not hiding
    By macwadu in forum AWT / Swing
    Replies: 8
    Last Post: 03-02-2011, 09:43 AM
  4. Hiding Code? Is it possible?
    By Krooger in forum Eclipse
    Replies: 7
    Last Post: 06-09-2009, 02:00 PM
  5. URL Hiding
    By sandeeprao.techno in forum Advanced Java
    Replies: 4
    Last Post: 11-20-2008, 12:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •