【问题标题】:How to only show a section of a JComponent/SwingNode/Java FX Pane如何仅显示 JComponent/SwingNode/Java FX 窗格的一部分
【发布时间】:2017-10-18 12:16:46
【问题描述】:
【问题讨论】:
标签:
java
javafx
components
jcomponent
pane
【解决方案1】:
如果你想简单地裁剪外部区域,请将节点包裹到Pane,设置负数LayoutXY和合适的MaxSize。当外部区域与其他Nodes 重叠时,可能需要裁剪。例如:
Pane viewPort = new Pane();
viewPort.getChildren().add(yourSwingNode);
// Top 200px and bottom 200px of yourSwingNode will be trimed.
yourSwingNode.setLayoutY(-200.0);
yourSwingNode.layoutBoundsProperty().addListener((o, ov, nv) -> {
viewPort.setMaxHeight(nv.getHeight() - 400.0);
});
// Set a clip for the layout bounds of Pane if you need
Rectangle clip = new Rectangle();
viewPort.layoutBoundsProperty().addListener((o, ov, nv) -> {
clip.setWidth(nv.getWidth());
clip.setHeight(nv.getHeight());
});
viewPort.setClip(clip);