View of the application javafx

2019-01-29 01:09发布

问题:

i was searching in google for hours and i still cant find the right answer, so i have a last chance to come here and ask.

i'm making school year JAVA FX project. I'm using NetBeans.

I have a point that i can see on the application i have. The problem is: I would like to have a big map (background) and I need to be able to move with my view. For example move by 50 to the right (x).

I have Application where I use Stage, Scene, StackPane.

I heard something about Dimensions in Java, but i can't use it in javafx application. Is there something similar, what can I use in my Application?

Thank you very much.

回答1:

What I think you are asking for is a Scene with a map (represented as an Image) in the background and controls layered on top of the map to allow interaction with the map at certain positions. Your question is a little unclear, so I'm not exactly sure if that is what you are asking.

If so, here is some sample code to implement that.

For the example use the mouse (or probably touch commands or trackpad scroll gestures - though I haven't a touch screen or trackpad to test it) to drag the map around. Click on the button to "Kill the evil witch".

The solution works by:

  1. Creating an ImageView to hold the background map.
  2. Constructing the scene contents in a StackPane over the stacked background ImageView.
  3. Wrapping the scene in a ScrollPane bound to the scene's size.
  4. Setting properties on the ScrollPane to make it pannable.