버튼 클릭시 ImageView 구성 요소의 이미지를 변경하려고합니다. 나는 그것이 지역의 이미지가 될 필요가있다. 계속 경로 오류가 발생하고 ImageIcon을 사용하여 이미지로 변환 할 수 없습니다. 이 작업을 수행하는 간단한 방법이 없습니까? JavaFX 장면 빌더를 사용하여 코드에서 ImageView 이미지 변경
package tictactoesimulator_alliebeckman;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
/**
*
* @author Allie
*/
public class FXMLDocumentController implements Initializable {
// my components
@FXML
public Label lblWinLose;
@FXML
public Button btnNewGame;
@FXML
public ImageView ivOne;
// Event handle for button click
@FXML
public void handleButtonAction(ActionEvent event) {
// here is where I'm having the issue I have the image file in my src folder
// I've tried using a ImageIcon and it wont convert to an Image?
// All I need is the image to change to the local image on button click
lblWinLose.setText("Clicked");
Image image = new Image("o.png");
ivOne = new ImageView(image);
}
@Override
public void initialize(URL url, ResourceBundle rb) {
}
}
프로젝트 레이아웃
이 이클립스 스크린 샷에서 볼 수있다 : 질문의 스크린 샷에서
Stack Trace를 게시 할 수 있습니까? –
java.lang.IllegalArgumentException : 잘못된 URL : 잘못된 URL 또는 자원을 찾을 수 없습니다. –