2013-07-27 6 views
0

:는 CSS를로드 할 수 없습니다 나는이 코드를 테스트하고있어

LayoutSample.java

import javafx.application.Application; 
import javafx.geometry.Insets; 
import javafx.scene.Scene; 
import javafx.scene.layout.FlowPane; 
import javafx.scene.paint.Color; 
import javafx.scene.shape.Rectangle; 
import javafx.stage.Stage; 

public class LayoutSample extends Application 
{ 

    public static void main(String[] args) 
    { 
     launch(LayoutSample.class, args); 
    } 

    @Override 
    public void start(Stage stage) 
    { 

     FlowPane flow = new FlowPane(); 
     flow.setPadding(new Insets(5, 5, 5, 5)); 
     flow.setVgap(5); 
     flow.setHgap(5); 
     flow.setPrefWrapLength(170); // preferred width allows for two columns 
     flow.setStyle("-fx-background-color: white;"); 

     //ImageView pages[] = new ImageView[8]; 
     for (int i = 0; i < 28; i++) 
     { 
//   pages[i] = new ImageView(
//     new Image(LayoutSample.class.getResourceAsStream(
//     "graphics/chart_" + (i + 1) + ".png"))); 
      flow.getChildren().add(generateRectangle()); 
     } 

     Scene scene = new Scene(flow); 
     ///// 
     String cssURL = "ButtonsDemo.css"; 
     String css = this.getClass().getResource(cssURL).toExternalForm(); 
     scene.getStylesheets().add(css); 
     //// 
     stage.setScene(scene); 
     stage.setTitle("Layout Sample"); 
     stage.show(); 
    } 

    public Rectangle generateRectangle() 
    { 

     Rectangle rect2 = new Rectangle(10, 10, 10, 10); 
     rect2.setId("app"); 
     rect2.setArcHeight(8); 
     rect2.setArcWidth(8); 
     rect2.setFill(Color.AZURE); 
     //rect2.setX(10); 
     //rect2.setY(160); 
     rect2.setStrokeWidth(1); 
     rect2.setStroke(Color.BLACK); 
     rect2.setWidth(220); 
     rect2.setHeight(180); 

     return rect2; 
    } 
} 

ButtonsDemo.css

#app { 
    -fx-background-color: 
    linear-gradient(to bottom, #f2f2f2, #d4d4d4); 
} 

을하지만 CSS 코드입니다 Rectangle 위에 렌더링되지 않습니다. 이것이 자바 코드가 맞다고 말할 수 있습니까? 나는 Rectangle Id를 설정하지 않는다고 생각한다.

답변

1

CSS가 제대로로드되었지만 적용하려는 노드 유형에 적용 할 수 없기 때문에 스타일 역할이 무시됩니다.

-fx-background-color을 사용하려면 노드는 Region에서 파생되어야합니다.

직사각형은 지역이 아닙니다.

두 유형 모두에 적용 할 수있는 속성 정의에 대해서는 CSS reference on RegionsRectangle을 참조하십시오.

-fx-fill을 사용하여 사각형에 그라데이션 채우기를 설정하면 실제로 원하는 것으로 추측됩니다. 그런 다음 채우기를 소스 코드로 설정하면 안됩니다.

관련 문제