How to get the dimensions of the area within the window of the scene?

Hello

I am able to get the size of a window using stage.getWidth () and stage.getHeight (), which gives the dimensions of the window, including the border. But how the size of the dimensions within the window, which is the area inside the border of the window?

I had created a way to understand this by calculating the difference between the sides of my initial scene and my step. I called this window filling, which is essentially the thickness of the border on the sides and up and down.

This method of calculation for available surface area in a window is not reliable when a window is maximized, because the thickness of the border of the window shrinks when enlarged. And if your stage size is larger than your scene, then you will get a wrong value.

There must be a way to get this area. I need it to do correctly scaling.

Thank you
Jose

Published by: jmart on 22 August 2012 23:58

I did it by adding a 'master' component to the stage

mainScene = new scene (masterPane, 430, 430);

The master component is just a container that contains all the content but will resize the window resize event and therefore will always have the right width and height.

masterPane = new Pane();
masterPane.getChildren () .add (root);

Due to that you can resize your content based on

Double screenWidth = masterPane.getWidth ();
Double screenHeight = masterPane.getHeight ();

Here is an example. You can zoom (scrollwheel), pan (click and drag) and Center + scale on the screen (middle button) (only if the content is a square, there is a bug if the content is greater than the width, which I had no time to eliminate now but you get the point)

import javafx.animation.Animation;
import javafx.animation.ParallelTransition;
import javafx.animation.ParallelTransitionBuilder;
import javafx.animation.RotateTransition;
import javafx.animation.RotateTransitionBuilder;
import javafx.animation.ScaleTransition;
import javafx.animation.ScaleTransitionBuilder;
import javafx.animation.Timeline;
import javafx.animation.TranslateTransition;
import javafx.animation.TranslateTransitionBuilder;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

public class Test extends Application
{
    Stage primStage;
    Scene mainScene;
    Group root;
    Pane masterPane;
    Point2D dragAnchor;
    double initX;
    double initY;

    public static void main(String[] args)
    {
        launch(args);
    }

    @Override
    public void init()
    {
        root = new Group();

        final Pane pane = new Pane();
        pane.setStyle("-fx-background-color: #CCFF99");

        pane.setOnScroll(new EventHandler()
        {
            @Override
            public void handle(ScrollEvent se)
            {
                if(se.getDeltaY() > 0)
                {
                    pane.setScaleX(pane.getScaleX() + pane.getScaleX()/15);
                    pane.setScaleY(pane.getScaleY() + pane.getScaleY()/15);
                }
                else
                {
                    pane.setScaleX(pane.getScaleX() - pane.getScaleX()/15);
                    pane.setScaleY(pane.getScaleY() - pane.getScaleY()/15);
                }
            }
        });

        pane.setOnMousePressed(new EventHandler()
        {
            public void handle(MouseEvent me)
            {
                initX = pane.getTranslateX();
                initY = pane.getTranslateY();
                dragAnchor = new Point2D(me.getSceneX(), me.getSceneY());
            }
        });

        pane.setOnMouseDragged(new EventHandler()
        {
            public void handle(MouseEvent me) {
                double dragX = me.getSceneX() - dragAnchor.getX();
                double dragY = me.getSceneY() - dragAnchor.getY();
                //calculate new position of the pane
                double newXPosition = initX + dragX;
                double newYPosition = initY + dragY;
                //if new position do not exceeds borders of the rectangle, translate to this position
                pane.setTranslateX(newXPosition);
                pane.setTranslateY(newYPosition);

            }
        });

        int x = 0;
        int y = -40;
        for(int i = 0; i < 5; i++)
        {
            y = y + 40;
            for (int j = 0; j < 5; j++)
            {
                final Rectangle rect = new Rectangle(x, y, 30 , 30);
                final RotateTransition rotateTransition = RotateTransitionBuilder.create()
                        .node(rect)
                        .duration(Duration.seconds(4))
                        .fromAngle(0)
                        .toAngle(720)
                        .cycleCount(Timeline.INDEFINITE)
                        .autoReverse(true)
                        .build();
                rect.setOnMouseClicked(new EventHandler()
                {
                    public void handle(MouseEvent me)
                    {
                        if(rotateTransition.getStatus().equals(Animation.Status.RUNNING))
                        {
                            rotateTransition.setToAngle(0);
                            rotateTransition.stop();
                            rect.setFill(Color.BLACK);
                            rect.setScaleX(1.0);
                            rect.setScaleY(1.0);
                        }
                        else
                        {
                            rect.setFill(Color.AQUAMARINE);
                            rect.setScaleX(2.0);
                            rect.setScaleY(2.0);
                            rotateTransition.play();
                        }

                    }
                });

                pane.getChildren().add(rect);
                x = x + 40;

            }
            x = 0;

        }

        pane.autosize();
        pane.setPrefSize(pane.getWidth(), pane.getHeight());
        pane.setMaxSize(pane.getWidth(), pane.getHeight());
        root.getChildren().add(pane);

        masterPane = new Pane();
        masterPane.getChildren().add(root);
        masterPane.setStyle("-fx-background-color: #AABBCC");
        masterPane.setOnMousePressed(new EventHandler()
        {
           public void handle(MouseEvent me)
           {
               System.out.println(me.getButton());
               if((MouseButton.MIDDLE).equals(me.getButton()))
               {
                   double screenWidth  = masterPane.getWidth();
                   double screenHeight = masterPane.getHeight();
                   double scaleXIs     = pane.getScaleX();
                   double scaleYIs     = pane.getScaleY();
                   double paneWidth    = pane.getWidth()  * scaleXIs;
                   double paneHeight   = pane.getHeight() * scaleYIs;

                   double screenScale  = (screenWidth < screenHeight) ? screenWidth : screenHeight;
                   int    screenSide   = (screenWidth < screenHeight) ? 0 : 1;                 

                   double scaleFactor = 0.0;
                   if(screenSide == 1)
                   {
                       scaleFactor = screenScale / paneWidth;
                   }
                   else
                   {
                       scaleFactor = screenScale / paneHeight;
                   }

                   double scaleXTo = scaleXIs * scaleFactor;
                   double scaleYTo = scaleYIs * scaleFactor;

                   double moveToX  = (screenWidth /2) - (pane.getWidth()  / 2);
                   double moveToY  = (screenHeight/2) - (pane.getHeight() / 2);
                   TranslateTransition transTrans = TranslateTransitionBuilder.create()
                       .duration(Duration.seconds(2))
                       .toX(moveToX)
                       .toY(moveToY)
                       .build();
                   ScaleTransition scaleTrans = ScaleTransitionBuilder.create()
                       .duration(Duration.seconds(2))
                       .toX(scaleXTo)
                       .toY(scaleYTo)
                       .build();
                   ParallelTransition parallelTransition = ParallelTransitionBuilder.create()
                      .node(pane)
                      .children(transTrans,scaleTrans)
                      .build();
                   parallelTransition.play();
               }
           }
        });

    }
    public void start(Stage primaryStage)
    {
        primStage = primaryStage;
        mainScene = new Scene(masterPane, 430, 430);
        primaryStage.setScene(mainScene);
        primaryStage.show();
    }
}

Tags: Java

Similar Questions

  • How to get the new activation key when some numbers are taken away and you have received?

    How to get the new activation key when some numbers are taken away and you have received?

    Have a laptop with windows 7 from Dell. Need to re install W7. And I have some numbers are taken as a result of its use.
    How can I get a new code activation or my complete activation code?
    Best regards, W7 user

    How to get the new activation key when some numbers are taken away and you have received?


    Have a laptop with windows 7 from Dell. Need to re install W7. And I have some numbers are taken as a result of its use.
    How can I get a new code activation or my complete activation code?

    Dell provided you with restore/recovery media and/or a way to restore the machine 'default' as a key sequence?  If so - you won't need the number--unless they just sent a DVD of Windows 7 nu - and they are usually not unless you ask.

    They have probably installed using their key, which means that even with a utility like Belarc Advisor or ProduKey - you will not get the product key that matches the one on the sticker.

    Some may have you take several different digital pictures of the sticker from different angles and see if you can decipher the missing characters like that (you'd be surprised to see how that works).

  • How to get the logical tab in the main area of 4.1.2 Data Modeler?

    Data Modeler.jpgI just installed Oracle Developer Data Modeler: Version 4.1.2.895.

    I was following section 2.1 development of the logic model

    http://docs.Oracle.com/CD/E48219_01/doc.40/e48205/tut_data_modeling.htm#DMDUG36169

    I used the example of library. I added the areas.

    Then I tried to create the books.

    The document says:

    1. In the main area (right) of the Data Modeler window, click the logical tab.
    2. Click the icon of the new entity.

    But I don't see the logical TAB on the right side at all.

    I see the Start Page. On the far right is the browser window. Basically, I see Messages - Log.

    On the left side, I have the browser window.

    Can someone tell me please how to get the logical TAB in the main area?

    Thanks in advance.

    Hello!

    In the browser with the right button on the logic model and select view.

    I hope this helps!

    Heli

  • During the import of my camera or a file in Lightroom 5 my pictures are too exposed by 1-2 stops, while they are well exposed on the screen of the device. How to get the "right-exposed images on the screen?

    During the import of my camera or a file in Lightroom 5 my pictures are too exposed by 1-2 stops, while they are well exposed on the screen of the device. How to get the "right-exposed images on the screen?

    There is an option in your Lightroom preferences, under the general tab, "treat JPEG files next to raw in form of images". If you have this option is checked, then Lightroom will import and view your first two and JPEG files. You use the active D-lighting on your camera? If you are, you must disable this feature.

  • How to get the balance of an element value

    Hello

    I have a requirement to obtain related information with balance. I am able to read the information on the element except balance.how to get the value of the particular item balance.

    for the application-> transfer and process-> queries with trust-> value the month selected and chosen balances button and queries with the obtained item name break it down the value of the balance.

    These values I want in my query.i tried backend with calling package by passing parameters like the number of transfer, balance the id and date but iam getting value "0".

    IAM new to hrms, Please help me on how to get this balance of values

    Thank you

    Hello

    It is not very clear what you want to display in the form of balance for a given range of dates.

    It depends on how you have configured your balances and periods and balance which you are referring.

    The API allows for a given only date that matches the date earned.

    Say, for example, that you have a "basic salary" defined with a "Treatment period assignment to Date" dimension and feed of the element that corresponds to the base salary.

    "If you need get the 'wage base Total' (balance?) for the period February 1, 2015 ' to March 31, 2015", then you need get dates earned for payroll passes made during that period and call the package above with the appropriate settings.

    Another way is by querying the tables/views directly: you can use, for example - it's perhaps easier to your situation:

    Select sum (nvl (pbv.value, 0))

    of pay_balance_values_v the VB.

    where pbv.balance_name = 'base salary.

    and pbv.database_item_suffix = '_ASG_PTD. '

    and pbv.assignment_id =

    and pbv.effective_date between to_date (' 01/02/2015 ',' dd/mm/yyyy')

    and to_date (' 31/03/2015 ',' dd/mm/yyyy');

    Kind regards
    Rajen

  • How to get the system screen resolution

    Hi all


    I'm developing a flex application in adobe flex3. When I draw components in the design area flex builder is set to "Fit to window". so application are displayed on my monitor(17") correctly, but when I try to run the same application to another computer or a laptop of 14" display screen is different than the screen of the monitor is short, I need to scroll down to see the full page. My question is how can I make sure that the application should search for uniform on different platform/different browsers and different monitors (regardless of the dimensions of the monitor).

    And how can get the screen resolution of system during execution?


    Thanks for all the help and support.

    Look in flash.system.capabilities.  Note that any application based on a browser usually does not control how big be.

    Alex Harui

    Flex SDK Developer

    Adobe Systems Inc..

    Blog: http://blogs.adobe.com/aharui

  • Re: How to get the Tempo to work properly?

    Hello

    I have problems with the service of Tempo.

    I don't get updates via this application (all the settings of this application are accurate, i.e. "full control"). I know this because there are updates available online to my laptop via the pilot site of toshiba.

    When I installed first Tempo, updates for about a month, I received, and then all of a sudden, no update came through. My firewall is blocking either of this application.

    I tried to reinstall the application, but no change in the situation.

    Does anyone know if ALL updates are available via the website of driver toshiba out tempo? Because, in the month that this service worked, I got an update of the bios, but I recently saw a bios update online and Tempo has not always reports that it is available.

    Any ideas on how to get the Tempo to work properly?

    Thank you.

    I saw in your other thread you have installed SP1 on your Vista laptop.
    There may be some compatibility problems between SP1 and Tempo

    And Yes, as far as I know Tempo bring all available updates!

  • I rolled again Firefox 4.0 to 3.6 and now my navigation bar still looks like instead of 3.6 4.0 how to get the old layout back?

    I rolled again Firefox 4.0 to 3.6 and now my navigation bar still looks like instead of 3.6 4.0 how to get the old layout back?

    The fastest way is to use the option 'Restore the default toolbar set' as shown here - https://support.mozilla.com/kb/Back+and+forward+or+other+toolbar+items+are+missing

  • How to get the card working on Tecra M1 WLAN?

    I just bought a 2nd hand Tecra M1. Great! It has installed XP but no Toshiba tool. I can't access my WLAN router. Seems like if WIFI connection is not yet installed. As I know from my Satellite Pro M30, there are Toshiba tools for this, they work smarter.

    Maybe I need drivers - WXP is material unknown when starting up - might be the WLAN device - who knows.
    When I check the network connections, I find 1934 and LAN adapter, but no WLAN device. I have already run the XP Wizard for WLAN connections, SSID and hexagonal key; but no WLAN device presents itself.

    Then, someone a idea how to get the job of WLAN?
    Is it possible to get the Toshiba M1 software or can I use my software SatPro?

    Thank you Jan so far

    It's good that you will find yourself, I think most of us would point on your ad when you have users with a similar problem. Sometimes it s really useful to have users like you who will investigate their cases.

    I'm now long enough a Member here, but every time I have met people who have solved problems like that, then I must say how much I appreciate it. :)

    Welcome and good weekend

  • Satellite A500 PSAM3A - how to get the HARD market under Vista 64-bit disk Protection System

    Hello

    I would like to know how to get the HARD drive Protection system up and running under Vista Home Premium 64 bit operating system. I downloaded the program 64 bit of Toshiba for this program and install it I tried but doesn't seem to work. I have uninstalled and try to install the program, but still does not work.

    Unable to find the problem, why it won't work. If anyone knows how to solve this problem it would be a great
    help for me. If anyone knows how to solve this problem please answer me as soon as possible.

    Thank you for your time.

    Kind regards
    Nigel.

    Hello!

    What you downloaded exactly on the Toshiba site?

    As written Akuma you must install first added value Package you will find also on the Toshiba site. Check this box!

    An interesting thing: it does not work if you are using the preinstalled operating system? It should have everything installed for your laptop.

    Good bye

  • How to get the icons to display correctly in the Finder?

    At the time of the "classic" Mac OS, if the icons are not correctly display in the Finder, we could 'rebuild the desktop file' to correct the problem. I've recently updated to Yosemite, and most things work well, but for some reason, most of the files in the Finder .webloc now show as blank icons (but not all; a few show the correct icon). There is no model, I can see: some very old .webloc files now show a white icon (where I know that their icons used to be correct), while the most recent show the icon of correct - although I just created four (by dragging the URL of the Safari, the usual method) which are all empty. Sometimes they appear with the older icon, with the symbol @ (although those who seem to have changed vacuum after running and restart maintenance). I tried from an external disk, repair permissions and repair the file system, as well as cleaning with the utility of Maintenance (which clears the web browser and other caches), nothing works. Does anyone know how to get the computer to display these icons correctly?

    May be a corrupt .plist.

    Make a backup, preferably 2 backups on 2 separate drives.

    Go to Finder and select your user folder. With this Finder window as the windshield, select Finder/display/display options for presenting or order - J.  When the display options opens, check "show the library folder. This should make your visible user library folder in your user folder.  Select the library. Then go to Preferences/com.apple.finder.plist and com.apple.desktop.plist.  Move the .plists on your desktop.

    Relaunch the Finder by restarting the computer and test. If it works fine, delete the plists from the desktop.

    If the same, return the .plists to where you obtained since, by crushing the latest.

    Thanks to leonie for certain information contained in this.

  • Chart WPF: How to get the limits of PlotArea and axes

    I can't find explicit methods to get limits of PlotArea and axes.

    Please let me know workarounds if they are available. Actually a post explains how to get the PlotArea limits using RangeCursor. Are there alternative means for shafts?

    The photo below shows what I did in WinForms with the methods GetBounds and HitTest. I would like to draw the ornaments on the chart in WPF.

    I have attached a code example of this look ornaments around the plot area and the scales.

    Note that this relies on implementation details of the current version of WPF controls for the ornaments of the scale, as it was more effective than gradually points to test in the graph using the GetScaleAt method. We have intentionally left much of the underlying primitive types with a minimum documentation, like us they have changed in the past and may change in the future. Although these exact members can be removed in a future release, we do not expect to provide an equivalent function and stabilize the primitive API over time.

  • How to get the IP address of the client when TCP connect on the server

    How to get the IP address of the client when TCP connect on the server.

    The only parameter obtained the login is the login ID.

    I assume you are using "Wait of TCP on the listening port" on the server. This returns the remote address and port (like out in option).

  • How to get the items on a loop at the same time during the execution of the loop for

    Hello

    I am a student. I would like to know how to get the outside loop counter values For in parallel so that the loop runs rather than obtaining the value finally outside the loop for future prospects for the answers.

    Thank you

    Frederick

    You already said yes, and you have said some of the different ways (registrants, locals, reference, queue, etc.). Since the information was provided to your request, the thread can be considered closed? If you want details about how to implement something, you must provide the details on what you are doing.

  • How to get the reference or the property of a member in OOP node?

    Hello world

    Is it possible to get the referral of a member in OOP?

    After you have created a class and an insert, a member of control in the cluster, I conclude that, when a right click on it, there is no element of "creat-> reference" or "create-> property node?

    So, how to get the reference or the property of a member in OOP node?

    Hello

    There are a few reasons that you can't do what you want to do:

    1 al ' LVOOP ordinary (as opposed to the DVRS in LabVIEW 2009, or some other framework / pattern design) are items of LabVIEW by value, as a cluster and therefore you can not create a reference to a class.

    2. a control of the object (this is what you get when you drop an object on a façade) is a 'black box' because you cannot look inside. This is to support the idea that the class data private. This means that you can't get a reference to all internal control when its on a façade

    3. check the references are valid only for the controls in the Panel before and therefore any class (or other piece of data of LabVIEW) on a wire / shift register / constant / anywhere other that of the façade, will have only the data portion of the available control.

    To access the items within a class, you create the accessor screws (you can create them easily by right-clicking a class (or the folder within the class) in the project tree and selecting New-> VI to access data members.) This VI would at least have a unbundle / bundle node (depending on whether its read/write) and could, if you have many more features such as range checking. You can use this VI whenever you want to read the Member your interested.

    I hope this helps.

    Shaun

  • How to get the string (specified by row and column) of txt file with labview

    Hello world

    How to get the string (specified by row and column) of txt file with labview

    THX

    As far as I know, a text file has no column.  Be more specific.  Do you mean something like the 5th word on line 4, where the words are separated by a space, and lines are separated by a newline character?  You can read from the spreadsheet String function and set the delimiter to a space.  This will produce a 2D channels table.  Then use the table to index and give the line number and column number.

Maybe you are looking for