应用程序javafx的视图 [英] View of the application javafx

查看:153
本文介绍了应用程序javafx的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在谷歌搜索了几个小时,我仍然找不到合适的答案,所以我有机会来这里问。

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.

我正在制作学年JAVA FX项目。我正在使用NetBeans。

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

我有一个观点,我可以在我的应用程序上看到。问题是:我想要一个大地图(背景),我需要能够随着我的观点移动。例如,向右移动50(x)。

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).

我有应用程序,我使用Stage,Scene,StackPane。

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

我听说过Java中的Dimensions,但我不能在javafx应用程序中使用它。是否有类似的东西,我可以在我的申请中使用什么?

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?

非常感谢。

推荐答案

我认为你要的是带有地图的场景(表示为图像)在背景和控件中分层放置在地图顶部,以允许在某些位置与地图进行交互。你的问题有点不清楚,所以我不确定这是不是你问的问题。

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. 创建 ImageView 来保存背景地图。

  2. StackPane中构建场景内容叠加后台 ImageView

  3. ScrollPane中包装场景绑定到场景的大小。

  4. ScrollPane 上设置属性以使其可以平移。

  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.

这篇关于应用程序javafx的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆