java - 列表中带有奇怪边框的JavaFx
问题描述
我有一个使用 flowless 项目的 JavaFX 列表。但是我得到了一个奇怪的边框(我没有启用任何边框并强制边框具有宽度= 0px),它存在并且具有渐变效果:
当我将单元格背景插入设置为-1时,边框消失了,所以我认为这个问题与背景有关。虽然这不是一个解决方案,因为如果我启用边框(我想要),渐变效果仍然存在。
有谁知道我怎样才能摆脱这个边界?
我使用带有最新 201 版本的 JavaFX 8。
编辑:我做了以下示例显示问题:
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.stage.Stage;
import org.fxmisc.flowless.Cell;
import org.fxmisc.flowless.VirtualFlow;
import org.fxmisc.flowless.VirtualizedScrollPane;
public class Main extends Application {
private ObservableList<Line> logLines;
private VirtualFlow<Line, Cell<Line, LineCell>> listView;
private VirtualizedScrollPane<VirtualFlow> listScrollPane;
public static void main(String[] args) {
launch(args);
}
public void start(Stage primaryStage) {
logLines = FXCollections.observableArrayList();
for(int i=1; i < 50; i++) {
logLines.add(new Line("Line "+i));
}
listView = VirtualFlow.createVertical(logLines, (line) -> Cell.wrapNode(new LineCell(line)));
listScrollPane = new VirtualizedScrollPane<>(listView);
Scene scene = new Scene(listScrollPane, 200, 600, Color.BLACK);
primaryStage.setScene(scene);
primaryStage.show();
}
private class Line {
private String text;
public Line(String text) {
this.text = text;
}
public String getText() {
return text;
}
}
private class LineCell extends TextFlow {
public LineCell(Line line) {
super();
Text t = new Text(line.getText());
t.setFill(Color.BLACK);
super.setStyle("-fx-background-color: green;");
super.getChildren().add(t);
}
}
}
谢谢!
解决方案
我找到了解决这个问题的方法。LineCell 不是扩展 TextFlow,而是扩展 StackPane,我将 TextFlow 添加到 Stackpane。
private class LineCell extends StackPane {
public LineCell(Line line) {
super();
Text t = new Text(line.getText());
t.setFill(Color.BLACK);
TextFlow tf = new TextFlow(t);
super.setStyle("-fx-background-color: green;");
super.getChildren().add(tf);
}
}
推荐阅读
- javascript - div显示/隐藏不起作用?
- office365 - Outlook Web 加载项 - 在 Outlook 客户端中获取和设置会议室
- java - 在后台 java 控制台应用程序上打印字母 X
- sql - 在 postgresql 查询中需要拆分行的帮助
- kubernetes - 在 Helm 图表中编写自定义函数
- css - 导航选项卡上的 CSS 形状
- ubuntu-16.04 - 无法在 Ubuntu 服务器上安装 docker
- redux - 不可变 JS:更新嵌套的动态对象
- php - 如何使用 laravel 5.4 使用 cartalyst sentinel 发送激活电子邮件/代码
- c# - 如何在 ASP.NET MVC5 Razor 语法中向 SelectListItem 添加类?