将第二个项目添加到我的堆栈窗格时,第一个项目将失去其Event / MouseOn。为什么?我该怎么办? JavaFX的 [英] When adding a second item to my stackpane, the first item loses its Event/MouseOn. Why? How can I fix? JavaFX
问题描述
我有一个堆叠的窗格。当我向堆栈窗格添加第二个项目时,两个都显示,但我不能再点击我的第一个项目了。它变得无法点击。
I have a stackpane. When I add a second item to my stack pane, both show up, but I can't click on my first item anymore. It becomes 'unclickable'.
我在.setonmouse中定义的内容不起作用。它适用于我的第二个项目。如果我切换它们在堆栈窗格中的顺序,那么另一个可以工作,但不能同时工作。
what ever I defined in my .setonmouse does not work. It works for my second item. If I switch the order they are in the stack pane, the other one works, but not both.
有没有解决这个问题?这就是我的程序的样子:
is there a fix for this? This is what my program looks like:
我希望我的'网格'始终居中。左侧有一些按钮位于列的中间,稍后会有右侧的按钮,网格顶部会有按钮/文本,稍后会在边距中显示按钮。
I want my 'grid' centered ALWAYS. There are buttons to the left centered in a column, there will be buttons on the right later on, and there will be buttons/Text on top of the grid and buttom in the margins later on too.
我希望所有内容都可以点击。
I want everything to be clickable.
http://img688.imageshack.us/img688/6025/examplerg.png
推荐答案
StackPane
以Z顺序订购商品:后者高于前者。所以,你的第二个项目点击所有鼠标点击,第一个项目(被第二个项目覆盖)没有任何结果。
StackPane
orders items in Z-order: latter above the former. So, your second item gots all mouse clicks and first one (being covered by second) doesn't get anything.
对于你所描述的布局,你可以使用BorderPane:
For layout you've described you can use BorderPane:
public void start(Stage stage) throws Exception {
BorderPane root = new BorderPane();
root.setCenter(new Rectangle(100,100, Color.RED));
root.setLeft(new Rectangle(10,10, Color.BLUE));
root.setRight(new Rectangle(10,10, Color.CYAN));
stage.setScene(new Scene(root,300,300));
stage.show();
}
这篇关于将第二个项目添加到我的堆栈窗格时,第一个项目将失去其Event / MouseOn。为什么?我该怎么办? JavaFX的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!