JavaFX ScrollPane border and background

后端 未结 7 2163
独厮守ぢ
独厮守ぢ 2020-12-14 10:56

I\'m having some problem regarding the default background and border of the ScrollPane. Using this style made the problem clearer to see.

setStyle(\"-fx-back         


        
相关标签:
7条回答
  • 2020-12-14 11:49

    Honestly, your question was not clear enough, but I am only providing this answer to help others if I can.

    What is causing this problem is you have the ScrollPane and inside it something called viewport that is bound to the ScrollPane. The properties that you apply for the ScrollPane object does not apply for the viewport. If you want to apply the properties for both ONLY, not the children too, you have to use the stylesheet property, not the style property itself, which uses in-line css code. For example, if you want to make the ScrollPane transparent, you have to apply the property for both, assuming the name of file is "scrollPane.css", like so:

    #mainScrollPane > .viewport {
        -fx-background-color: transparent;
    }
    
    #mainScrollPane {
        -fx-background-color: transparent;
    }
    

    However, you need to apply a special Id property for the ScrollPane object, so it does not apply for the children:

      ScrollPane scrollPane = new ScrollPane(root);
      scrollPane.setId("mainScrollPane");
      scrollPane.getStyleSheets().add("scrollPane.css");
    
    0 讨论(0)
提交回复
热议问题