Seems like this should be easy and obvious but I can't find the answer anywhere. I'm using JavaFX 2 and I need to find the width and height of the region of a node that is currently being displayed on screen to the user (NOT the width and height of the node in the whole layout).
So if the window is scrolled so that my node is halfway off the edge to the right, I'd expect to get a displayed width of half the node's width and a displayed height equal to the full height. Should be easy; isn't. Anyone know how it can be done?
A half-acceptable solution for me would be to use the dimensions of the window itself. Is this the same as the width / height of the Stage?
Thanks
Isn't this a simple calculation using the viewport dimensions of the scrollpane and the coordinates/dimensions of your node?
It would be easierto help if you could post a simple testcase to experiment with.
Related
I am looking to initially position my Scene's Camera Z-Distance away from a Group in order to make it so that the bounds of this Group will fit into the scene and be as big as possible. The group consisting of a flat plane with some boxes extending towards the camera (think of a bookshelf where the back of the bookshelf is Z=0). The Group and Scene will be varying widths and heights i.e., initial size of bookshelf 100w,50h, scene 1000w 400h.
I initially thought that I could attempt to find the distance using tan(FoV) = sceneHeight / distance; but that didn't work at all. I have looked at a few examples that approach it that way as well, but to no avail have I got this working. I am wondering if I would have to work with the object's initial height i.e., 300, and compare it to the height I am looking for i.e., 1920.
Any help is appreciated, thank you.
I am currently trying to get an image view containing an image to move from top of the screen downwards. When it reaches the buttom of the screen i'd like to switch direction going upwards again.
My problem is i can't find the exact spot, where i should make the image view change direction. My screen has a very high resolution and therefore i've set my os, windows, to enlarge all components. I can therefore not use my screen size to calculate how many pixels there are from top to bottom.
Therefore i use following code to get height of screen:
Screen screen = Screen.getPrimary();
Rectangle2D bounds = screen.getVisualBounds();
bounds.getHeight();
My Imageview is initialized at point (0,0) and i can therefore at any given time get the y-koordinate of my top left corner by using imageview.getY()
Therefore i should move it downwards until the value of imageView.getY() + height the image view equals the height of the screen.
But this solution seems to make my image view switch direction a bit before it reaches the bottom of the screen.
For calculating height of image i use the method imageView.getFitHeight();
I suspect imageView.getFitHeight for delivering the height desired by the imageview before it is actually determined by the underlying anchor pane and therefor i am not sure imageView.getFitHeight() actually delivers the height of the imageView. I can't seem to find any other method in imageView which regards height of the imageView.
I don't know how to make the imageview switch direction exactly at the bottom, can anybody help?
Regards Martin
I'm trying to create a game for Android device and I have a small question about the rendering of the scene. Effectively I want to draw a square of a precise size but I'm not pretty sure about the way I can get the coordinates of the border of the screen in openGL dimension. My application is set in landscape mode, so computation looks easier.
I have drawn a square with a border size of 2 and I have the impression that the square takes all the height of the screen. Since I know the resolution of my screen which is equal to 1920*1080, I can compute the width of my scene. Then, by drawing several squares I found the coordinates of on corner.
This way of computing the coordinates are a bit weird and I'm not pretty sure that the computation will always lead to a good answer. Is there a nicer way and obviously a better way to compute those coordinates ?
Thank you in advance !
I have a GridLayout I'm making which is populated with a bunch of pictures. The GridLayout itself is set to SizeFull(), as is each individual image in the grid.
The grid with the pictures is within another grid, and that grid has relative sizes set.
With this set up, the grid of pictures stays within the spot I want it to, properly resizing to fit within the space they should, but the pictures do not retain their proper square proportions. They squish fat or skinny however they want. I want them to retain the original proportions, though, so they expand to fill their available area as much as possible while retaining those proportions.
If I set the width to 100%, or the height to 100%, and leave the other undefined, then it retains the proportions, and properly expands to fit the one that is set to 100%, but the other spills outside the nested grid layout's spot in the upper grid layout.
Anyone know how to do this?
Have you tried setting the width and height as percentage?
So on an image of 80 by 120 pixels:
setWidth(66, Unit.PERCENTAGE)
setHeight(100, Unit.PERCENTAGE)
I have a JTree on a JScrollPane as part of my GUI. I've set up an AncestorListener where I respond to the ancestorAdded event. In the event, I would like to automatically expand as many visible nodes as possible. By visible, I mean that I want to expand as many nodes as possible such that the total height of the tree does not exceed the maximum height of the JScrollPane's viewport. If my viewport had 500px of visible space, I want the tree expanded until the total expanded height is less than or equal to 500px.
I've tried to achieve this a few different ways. It boils down to this: I can't seem to retrieve an updated height for the tree after programatically expanding a node. How can I recalculate the height of the tree? tree.getHeight(), for example, always returns the same value even after I expand a node. Invoking tree.invalidate() between calculations didn't help either.
How can I recalculate the height of the tree?
Maybe getVisibleRowCount()*getRowHeight() will give you the correct size.
The documentation for getRowHeight() states that it may return <= 0 and leave the row height up to the renderer, which may be the case for you as you're using a JTreeTable.