2
我创建图像的原始图像,供用户选择。我想要的形象来改变其颜色,一旦用户点击它javafx图像颜色变化
FileInputStream seats_fileInputStream = new FileInputStream("seat.png");
Image seats_image = new Image(seats_fileInputStream,50,50,false,false);
ImageView[] seats = new ImageView[30];
for(int i = 0;i<30;i++){
seats[i] = new ImageView(seats_image);
}
HBox seatsRaw_hbox[] = new HBox[5];
VBox seatsLine_vbox = new VBox();
int seatsCount = 0;
for(int i=0;i<5;i++){
seatsRaw_hbox[i]= new HBox();
for(int j=0;j<6;j++){
seatsRaw_hbox[i].getChildren().addAll(seats[seatsCount]);
seatsCount++;
}
seatsLine_vbox.getChildren().add(seatsRaw_hbox[i]);
}
BorderPane Test = new BorderPane();
Test.setCenter(seatsLine_vbox);
我试着去改变形象,以绿色,一旦它被点击:
Color targetColor = Color.GREEN;
ColorAdjust colorAdjust = new ColorAdjust();
colorAdjust.setSaturation(targetColor.getSaturation());
colorAdjust.setHue(targetColor.getHue());
colorAdjust.setBrightness(targetColor.getBrightness());
seats[0].setOnMouseClicked(e->{
seats[0].setEffect(colorAdjust);
});
但我不断收到奇怪的颜色
原单图像:
奇怪的结果我得到了一次,我点击:
_“我不断收到奇怪的颜色” _ - 请解释,并提供一些样品。 –
'seat.png'图像又如何显示? – fabian
@JimGarrison我已经编辑问题 – MrRizk