我实现了JavaFX教程中的拖放示例。
当我将标签拖到目标TabPane上时,我成功地添加了效果:
tabPane.setOnDragEntered(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
/* the drag-and-drop gesture entered the target */
/* show to the user that it is an actual gesture target */
if (event.getGestureSource() != tabPane
&& event.getDragboard().hasString()) {
tabPane.setCursor(Cursor.MOVE);
tabPane.setEffect(new Glow());
}
event.consume();
}
});
tabPane.setOnDragExited(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
/* mouse moved away, remove the graphical cues */
tabPane.setCursor(Cursor.DEFAULT);
tabPane.setEffect(null);
event.consume();
}
});但我想让目标TabPane的边框变绿,而不是添加光晕效果。这个是可能的吗?
发布于 2013-07-17 00:54:28
您可以在TabPane上设置样式(之后将其设置为空白字符串):
tabPane.setStyle("-fx-padding: 1; -fx-background-color: green, -fx-control-inner-background; -fx-background-insets: 0, 1;");或如果你想变得很酷,你可以在一个CSS样式表中完成这一切(当你开始拖动时,将styleClass "dragTab“添加到所有的标签窗格中(并在拖动结束时移除)。它至少消除了两个鼠标监听器。
.dragTab:hover {
-fx-padding: 1;
-fx-background-color: green, -fx-control-inner-background;
-fx-background-insets: 0, 1;
}发布于 2019-02-02 18:06:33
这对我来说很有效:
tabPane.setStyle("-fx-border-style:solid; -fx-padding: 1; -fx-background-color: green;");或者为-fx-border-style属性使用其他可能的值,例如双精度、虚线、...
https://stackoverflow.com/questions/17676574
复制相似问题