2

我有一个 JavaFX 2.2 TilePane 有几个项目(孩子)。我添加了 css,以便在鼠标悬停时,项目的比例设置为 1.2。默认情况下,子节点的顺序定义了首先绘制的节点和最后绘制的节点。有没有办法让悬停项目高于所有其他项目,而不诉诸 toFront() 并使其成为最后一个项目(将其移动到最后)。这个问题类似于https://stackoverflow.com/questions/13893514/scaling-children-in-a-flowpane-makes-the-children-clip-eachother(仍未得到答复)。

该问题的屏幕截图位于:http: //vladeck.files.wordpress.com/2013/03/javafx_tilepane.png ?w=640

4

1 回答 1

2

解决方案/解决方法

  1. 使用GridPane而不是TilePane
  2. 当用户单击网格中的某个项目时,在该项目上调用toFront

示例代码

我将以下代码添加到基于网格布局的计算器中,该网格布局看起来类似于示例屏幕截图中的平铺布局。使用修改后的应用程序,我没有遇到计算器按钮重叠的情况。令我惊讶的是,虽然它们看起来有点奇怪,但按比例缩放的按钮使计算器更易于使用......

button.setOnMouseEntered(new EventHandler<MouseEvent>() {
  @Override public void handle(MouseEvent mouseEvent) {
    button.toFront();
    button.setScaleX(1.6); button.setScaleY(1.6);
  }
});
button.setOnMouseExited(new EventHandler<MouseEvent>() {
  @Override public void handle(MouseEvent mouseEvent) {
    button.setScaleX(1); button.setScaleY(1);
  }
});

计算器 image1 计算器 image2


背景

As you note, the overlapping issue is unresolvable in some stock Panes like TilePane. This is because the z-order as well as the relative layout position of a node are both defined by the relative position of the node in the TilePane's child list. In such Panes, you cannot change the z-order and bring it to the front without also moving the node to the last layout position in the TilePane.

A GridPane does not suffer from the same issues as a TilePane because it's child node list order only defines the z-order of it's child nodes, not the layout positioning of those child nodes.

Is there a way (a hack?) to implement my own code of retrieving the children order for drawing when JavaFX repaints TilePanel?

Yes, you could hack the TilePane code if you have the skills.

于 2013-03-30T09:52:30.230 回答