2017-09-17 1 views
0

javafx.scene.control.ColorPicker을 내 UI에서 흐리게하지 않고 사용하지 않도록 설정하려고했습니다. 내가 활성화 된 것으로 보이기를 원한다는 것을 의미하지만, 어떤 명령에도 반응하지 않고, 마우스 클릭시의 색상 표를 보이지도 않습니다 (실제로는 비활성화 됨). 이 동작은 시스템 상태 (즉, 색상 선택기가 정상적으로 작동 할 때도 있음)에 따라 정상적인 동작과 호환됩니다. 다음과 같이어둡게 처리하지 않고 JavaFX ColorPicker를 비활성화하는 방법은 무엇입니까?

내가 몇 가지 옵션을 시도했지만, 아무도이 일 것 같았다 :

1. setEditable(boolean) :

myColorPicker.setEditable(false); 

이 그냥 작동하지 않습니다, 색상 선택기는 편집 할 수있는 상태로 유지됩니다 . 함께

2. setDisable(boolean)setOpacity(double) :

myColorPicker.setDisable(true); 
myColorPicker.setOpacity(1.0f); 

이것은 색상 선택기 실제로 편집 할 수 없습니다 만들고, 그 결과 색상 선택기 조금 덜 단지 setDisable(true)를 사용하는 것보다 희미하게 나타납니다,하지만 여전히하지 성상 사용 가능한 색상 선택기은 위의 방법은 내 콘솔에서 해당 메시지를 인쇄하지만, 색상 선택기는 여전히 마우스 클릭에 응답

myColorPicker.setOnMouseClicked(new EventHandler <MouseEvent>() { 
    public void handle(MouseEvent event) { 
     System.out.println("Mouse clicked."); 
    } 
}); 

myColorPicker.setOnMousePressed(new EventHandler <MouseEvent>() { 
    public void handle(MouseEvent event) { 
     System.out.println("Mouse pressed."); 
    } 
}); 

myColorPicker.setOnMouseReleased(new EventHandler <MouseEvent>() { 
    public void handle(MouseEvent event) { 
     System.out.println("Mouse released."); 
    } 
}); 

(색상 표를 보여주고 :

3. 빈 구현과 onMouseClick(), onMousePressed()onMouseReleased() 재정의 새로운 색상을 선택할 수 있습니다. 또한 setOnAction(EventHandler<ActionEvent>)을 덮어 쓰려고했지만 같은 효과가 있습니다 (색상 선택기를 클릭했을 때 콘솔 출력이 없다는 것을 제외하고). 나는 실제로 내 문제를 해결하기 위해 setEditable(boolean) 예상

.elementColor { 
    -fx-cursor: hand; 
    -fx-background-color: #fff; 
    -fx-focus-color: transparent; 
    -fx-faint-focus-color: transparent; 
    -fx-pref-width: 50.0; 
} 

, 요소 성상을 유지하고 무시로 : 내 CSS의 exerpt 여기

<VBox fx:controller="mypackage.ElementConfigWidget" 
    xmlns:fx="http://javafx.com/fxml" fx:id="root" styleClass="elementConfigPane"> 
    <HBox id="elementInfo"> 
     (...) 
     <ColorPicker fx:id="elementColor" styleClass="elementColor" /> 
    </HBox> 
(...) 
</VBox> 

입니다 : 여기

는 내 FXML의 발췌 한 것입니다 입력 동작. 내가 뭘 놓치고 있니?

고맙습니다.

답변

1

나는 1.0

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.ColorPicker; 
import javafx.stage.Stage; 

public class Main extends Application { 

    public static void main(String[] args) { 

     launch(args); 
    } 

    @Override 
    public void start(Stage primaryStage) throws Exception { 

     ColorPicker myColorPicker = new ColorPicker(); 

     myColorPicker.setDisable(true); 
     myColorPicker.setOpacity(1.0); 

     Scene s = new Scene(myColorPicker); 
     s.getStylesheets().add(this.getClass().getResource("test.css").toExternalForm()); 

     primaryStage.setScene(s); 
     primaryStage.show(); 
    } 

} 

그리고 test.css

.color-picker > .label:disabled { 
    -fx-opacity : 1.0; 
} 
+0

큰 일부 CSS 당신이 (참) setDisable 필요 .Also 및 불투명도를 달성하기 위해 관리! CSS가 트릭을 만들었습니다. :) –

관련 문제