2014-12-14 6 views
0

나는 3 개의 간단한 버튼 인 커스텀 컨트롤을 가지고있다. 컨트롤은 연결된 응용 프로그램의 작업을 처리하지만 이유 때문에 외부 스테이지에 있어야합니다.JavaFX에서 모든 장면, 스테이지 및 컨트롤이 투명 할 수 있습니까?

그것에 대해 짜증나는 점은 모든 단추 사이가 흰색 배경이라는 것입니다.

나는 그것을 제거하기 위해 다음의 모든 시도했다 :

  • 초기화 StageStyle을 투명
  • 선언 장면에 투명한 배경 : new Scene(Node, X, Y, Color.TRANSPARENT);
  • 선언 장면 NULL 배경 : new Scene(Node, X, Y, null);
  • HBox를 확장 한 컨트롤이 있습니다. .setStyle("-fx-background-color : rgba(0, 0, 0, 0);");

이들 모두는 백그라운드의 모양을 제거하지 못했습니다. Windows Forms에서이 작업을 수행했지만 JavaFX로 할 수 있습니까?

답변

1

당신은

  • 단계의 투명도를 설정해야
  • 장면
  • 루트 클래스 (또는 내 케이스 hbox에, 나는 루트를 선호)

이 작품 나를 위해 :

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.layout.HBox; 
import javafx.scene.paint.Color; 
import javafx.stage.Stage; 
import javafx.stage.StageStyle; 

public class Main extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     try { 

      HBox hbox = new HBox(); 
      hbox.setSpacing(12); 

      Button button1 = new Button("Button 1"); 
      Button button2 = new Button("Button 2"); 
      Button button3 = new Button("Button 3"); 

      hbox.getChildren().addAll(button1, button2, button3); 

      Scene scene = new Scene(hbox, Color.TRANSPARENT); 

//   scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); 
      scene.getRoot().setStyle("-fx-background-color: transparent"); 

      primaryStage.initStyle(StageStyle.TRANSPARENT); 
      primaryStage.setScene(scene); 
      primaryStage.show(); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 

그건 디 rect 용액.

enter image description here

: 여기

.root { 
    -fx-background-color: transparent; 
} 

응용 프로그램 코드를 통해 존재와 스크린 샷이다 : 물론 대신에 스타일을 설정하는 것은 바로이 스타일 시트 application.css를 사용하는 것이 더 연습이다

관련 문제