我正在尝试创建一个可视组件,该组件显示带有测量线的圆盘,以显示来自源的当前值。
一切正常,但是当我掩盖容器(窗格)以减少可见区域时,图像显示为变暗。
这是代码:
主.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
FXMLLoader loader = new FXMLLoader(
getClass().getResource("sample.fxml"));
Parent root = loader.load();
primaryStage.setTitle("Clock Test");
primaryStage.setScene(new Scene(root, 800, 200));
primaryStage.show();
Controller controller = loader.getController();
controller.initClock();
}
public static void main(String[] args) {
launch(args);
}
}
Controller.java [更新]
package sample;
import javafx.fxml.FXML;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.SubScene;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Cylinder;
import javafx.scene.shape.Rectangle;
public class Controller {
@FXML private Pane clock;
public void initClock() {
PerspectiveCamera camera = new PerspectiveCamera();
camera.setTranslateX(-150);
camera.setTranslateY(-32.5);
camera.setTranslateZ(-600);
Group group = new Group();
SubScene subScene = new SubScene(group, 300, 65);
subScene.setCamera(camera);
Rectangle rectangle = new Rectangle();
rectangle.setArcWidth(1);
rectangle.setArcHeight(1);
rectangle.setX(0);
rectangle.setY(0);
rectangle.setWidth(300);
rectangle.setHeight(65);
Cylinder cylinder = new Cylinder(600, 65);
PhongMaterial material = new PhongMaterial();
Image diffuseMap
= new Image(getClass()
.getResource("/images/clock.png")
.toExternalForm());
material.setDiffuseColor(new Color(1, 1, 1, 1));
material.setDiffuseMap(diffuseMap);
cylinder.setMaterial(material);
PointLight light = new PointLight();
light.setColor(Color.WHITE);
light.setTranslateX(0);
light.setTranslateY(50);
light.setTranslateZ(-800);
group.getChildren().addAll(cylinder, light);
clock.getChildren().add(subScene);
}
}
示例.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<GridPane alignment="center" hgap="10" vgap="10" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.172-ea" fx:controller="sample.Controller">
<children>
<Pane fx:id="clock" prefHeight="65.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
</children>
<columnConstraints>
<ColumnConstraints minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints minWidth="300.0" maxWidth="300.0" prefWidth="300.0" />
<ColumnConstraints minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" />
<RowConstraints />
<RowConstraints minHeight="10.0" prefHeight="30.0" />
</rowConstraints>
</GridPane>
在这里克隆它:
git clone https://your_username@bitbucket.org/diegoluisr/meter3d.git