【问题标题】:ControlsFX LineBorder with title has white background rather than transparent带有标题的 ControlsFX LineBorder 具有白色背景而不是透明
【发布时间】:2015-08-14 02:02:51
【问题描述】:

所以当我制作一个标题为 ControlsFX 的边框时,我会遇到这个奇怪的故障:

看到“嗨”周围的白色区域了吗?那不应该在那里。奇怪的是,如果我给另一个Tab添加相同的边框(新实例),那么它就变得正常了:

这是生成边框的代码:

Node calculateBorderd2 = Borders.wrap(new TextField()).etchedBorder().title("hi").buildAll();
bottomBorderPane.setRight(calculateBordered2);

这只能在我的程序中重现。我试图创建 mcve,但如前所述,我无法重现它。添加第二个边框 100% 解决了问题(有时不是)。

我很确定这是 JavaFX 或 ControlsFX 中的错误。我查看了我所有的代码,找不到任何与此相关的东西(但显然有)。我正在使用一半和一半的 FXML。

我查看了反编译的Borders类,发现背景生成为透明,如果场景不等于null,则为其他:

private void updateTitleLabelFill() {
    Scene s = n.getScene();
    if(s == null) {
    BackgroundFill fill = new BackgroundFill(Color.TRANSPARENT, (CornerRadii)null, (Insets)null);
    this.titleLabel.setBackground(new Background(new BackgroundFill[]{fill}));
    } else {
        this.updateTitleLabelFillFromScene(s);
        s.fillProperty().addListener(new WeakInvalidalionListener(this.updateTitleListener));
     }
}

private void updateTitleLabelFillFromScene(Scene s) {
    s.snapshot(new Callback() {
        public Void call(SnapshotResult result) {
            WritableImage image = result.getImage();
            PixelReader reader = image.getPixelReader();
            int start = (int)titleLabel.getLocalToSceneTransform().getTx();
            int finish = (int)((double)start + titleLabel.getWidth());
            int startY = (int)titleLabel.getLocalToSceneTransform().getTy();
            int finishY = (int)((double)startY + titleLabel.getHeight());
            HashMap map = new HashMap();

            Color color;
            for(int max = startY; max < finishY; ++max) {
                for(int column = start; column < finish; ++column) {
                    try {
                        color = reader.getColor(column, max);
                        if(map.containsKey(color)) {
                            map.put(color, Integer.valueOf(((Integer)map.get(color)).intValue() + 1));
                         } else {
                             map.put(color, Integer.valueOf(1));
                         }
                     } catch (Exception var14) {
                         ;
                     }
                 }
             }

             double var15 = 0.0D;
             color = null;
             Iterator fill = map.keySet().iterator();

             while(fill.hasNext()) {
                 Color colorTemp = (Color)fill.next();
                 if((double)((Integer)map.get(colorTemp)).intValue() > var15) {
                     color = colorTemp;
                     var15 = (double)((Integer)map.get(colorTemp)).intValue();
                 }
             }

             BackgroundFill var16 = new BackgroundFill(color, (CornerRadii)null, (Insets)null);
             titleLabel.setBackground(new Background(new BackgroundFill[]{var16}));
             return null;
         }
     }, (WritableImage)null);
 }

以前有人遇到过这个问题吗?如果您想查看我的整个代码(数十个类),我可以将您添加到我的 BitBucket 存储库以查看全部内容。

【问题讨论】:

    标签: java border javafx-8 controlsfx


    【解决方案1】:

    您的标题边界在哪里?

    就像https://bitbucket.org/controlsfx/controlsfx/issues/441/background-color-of-borders-is-incorrect 中显示的一样,直接计算背景。

    因此,如果您的边框正在移动,或者出现在另一个物体上方,我们可能会遇到选择错误颜色的问题。我会尽快在 ControlsFX 中解决这个问题

    【讨论】:

      猜你喜欢
      • 2014-06-24
      • 2013-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-21
      • 2021-03-26
      • 1970-01-01
      相关资源
      最近更新 更多