【发布时间】:2018-05-18 03:51:45
【问题描述】:
我需要显示一个带有 InnerShadow 效果的矩形作为我的 JavaFX 节点的背景。每个节点都需要调整大小。我正在使用一个抽象基类来实现这一点,该基类具有一个带有 InnerShadow 的矩形作为其子级之一的区域,以及由此类的具体实现提供的一个区域作为其另一个子级。
当我将一个或多个 ComboBoxes 添加到子区域时,会出现此问题。单击 ComboBox 没有任何效果,即它们不会显示其下拉项目列表。
我已尝试将 Rectangle 缩小(即 10x10 像素),使其不会与 ComboBoxes 重叠。这没什么区别。
private void createNodeWithBackground() {
pane = new Region() {
@Override
public void resize(double width, double height) {
super.resize(width, height);
backing = new Rectangle(width, height);
InnerShadow shadeEffect = new InnerShadow();
shadeEffect.setWidth(w/2);
shadeEffect.setHeight(h/2);
shadeEffect.setInput(new ColorAdjust(-0.1, 0.2, -0.1, 0.1));
backing.setEffect(shadeEffect);
getChildren().clear();
getChildren().addAll(backing, getBodyNode());
}
};
getChildren().add(pane);
}
/**
* The concrete class provides a node to be displayed on top of the
* Rectangle with the InnerShadow.
* This might be a VBox containing a ComboBox and other nodes.
*/
protected abstract Region getBodyNode();
从场景中移除矩形会导致组合框按预期显示下拉列表。
【问题讨论】:
-
如果您对自己的解决方案不满意,请发帖minimal reproducible example。