想象一下,我们有一个AnchorPane
,它有孩子Pane
,我们有Button
,例如。
我想要这个Button
仅在此Pane
内显示。
换句话说,如果它不完全在Pane
之内,它将被Pane
边缘削减。现在Button
即使不在Pane
矩形中也可以看到。如何限制物品的可见性?
7
A
回答
15
这就是节点的clip。
实施例:
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class ClipTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Group root = new Group();
StackPane pane = new StackPane();
pane.setMaxWidth(100);
pane.setMaxHeight(100);
pane.setLayoutX(50);
pane.setLayoutY(50);
Rectangle rect = new Rectangle(100, 100);
rect.setFill(null);
rect.setStroke(Color.RED);
Rectangle rect2 = new Rectangle(150, 150);
rect2.setFill(Color.BLUE);
pane.getChildren().addAll(rect2, rect);
root.getChildren().add(pane);
// Rectangle clip = new Rectangle(100, 100);
// clip.setLayoutX(25);
// clip.setLayoutY(25);
// pane.setClip(clip);
Scene scene = new Scene(root, 250, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
}
这产生:
在取消关于剪辑中的线生产:
6
可以使用clipping FUNC达到这个目标。
public class ClipPane extends Application {
@Override
public void start(Stage stage) throws Exception {
Pane clipPane = new Pane();
clipPane.setStyle("-fx-border-color: red;");
clipPane.setPrefSize(200, 200);
Rectangle rect = new Rectangle(200, 200);
clipPane.setClip(rect);
Button btn = new Button("Hello, world!");
btn.relocate(120, 0);
clipPane.getChildren().add(btn);
AnchorPane root = new AnchorPane();
root.getChildren().add(clipPane);
AnchorPane.setTopAnchor(clipPane, 50.);
AnchorPane.setLeftAnchor(clipPane, 50.);
stage.setScene(new Scene(root, 300, 300));
stage.show();
}
public static void main(String[] args) { launch(); }
}
4
另一种方法,使用observables。删除窗格边界之外的项目(如css oveflow:hidden):
// create rectangle with sizes of pane,
// dont need to set x and y explictly
// as positions of clip node are relative to parent node
// (to pane in our case)
Rectangle clipRect = new Rectangle(pane.getWidth(), pane.getHeight());
// bind properties so height and width of rect
// changes according pane's width and height
clipRect.heightProperty().bind(pane.heightProperty());
clipRect.widthProperty().bind(pane.widthProperty());
// set rect as clip rect
pane.setClip(clipRect);
相关问题
- 1. 如何在bugzilla中限制产品内部的组可见性权限
- 2. 限制通过可见性发现的产品?
- 3. 如何限制购物车产品Prestashop
- 4. 如何限制grails中域属性的可见性?
- 5. 可添加到购物车的物品数量限制 - simpleCart
- 6. 限制SWF文件的可见性
- 7. 如何限制目标C中的枚举值的可见性?
- 8. 如何限制类的可见性到特定的其他类?
- 9. 限制Silverlight/WPF行为可见性
- 10. 如何限制地址栏中的URL修改可见性?
- 11. 如何限制SharePoint 2010中的功能可见性?
- 12. Bootstrap传送带控制下一行中的可见物品
- 13. 只显示物品时可见
- 14. 如何控制sitemapnode的可见性?
- 15. 如何限制箱子丢弃的物品数量?
- 16. 如何限制允许的物品留在客户的购物车Magento的
- 17. 如何无限循环一列物品?
- 18. Three20中的物业可见性变化
- 19. 如何根据粘性物品的尺寸制作固定粘性物品的“边缘顶部”?
- 20. 如何通过限制和降序获取物品索引createAt
- 21. 限制woocommerce购物车中的物品数量?
- 22. 如何使用方向更改控制视图可见性(可见/不可见)?
- 23. magento - 如何调试?产品不可见,克隆产品不可见,新产品可见
- 24. 如何限制SP列表中的编辑仅限于拥有物品?
- 25. 如何将DataGridTemplateColumn的可见性绑定到textBlock的可见性
- 26. Drupal基于购物车中的产品的PHP块可见性规则
- 27. 不能在回收站中使用的物品的可见性查看
- 28. 如何使用jquery限制可放置div(购物车)接受的物品的数量
- 29. 如何限制类声明之外的名称空间的可见性?
- 30. 如何将Netsuite购物车中的商品数量限制为可用商品数量
虽然...这很棒,剪辑的初始大小似乎被忽略。有没有办法以任何方式修改它以保留标签边界? – Line 2018-02-20 06:28:11