ボタンをクリックしてImageViewコンポーネントのイメージを変更しようとしています。私はそれがローカルイメージであることが必要です。私はパスのエラーを取得し続け、私はImageIconを使用してイメージに変換することはできません。これを行う簡単な方法はありませんか?JavaFXシーンビルダを使用してコード内のImageViewイメージを変更する
プロジェクトのレイアウトはすべて、このEclipseのスクリーンショットで見ることができ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またはリソースが見つかりません –