상단에 버튼 행이 있고 측면에 버튼 행이있는 프로그램을 만듭니다. 위쪽 단추는보기를 제어하고 측면 단추는보기에서 참조 할 개체를 제어합니다.JavaFX : 새로운 값으로 경계 판의 중심보기를 업데이트하는 방법
내 메인/루트보기가 경계선입니다.
이 단추 중 하나를 클릭하면 MainController에서 값을 변경 한 다음 이러한 새 값으로 가운데보기를 다시로드해야합니다. 값을 변경하고 이러한 값에 따라 새 센터를 설정하는 메소드를 작성하는 것이 매우 간단하다고 생각했습니다.
그러나 테스트 할 때 이미 표시하도록 요청한 두 값을 표시 할 수 있지만 실행할 때마다 큰 오류가 발생합니다. 다음과 같이
내 MainViewController 보인다 :
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class MainViewController extends Application {
@FXML
private Button cabin1;
@FXML
private Button cabin2;
@FXML
private Button tab1;
@FXML
private Button tab2;
@FXML
public void setCabinOne() throws IOException {
cabinIndex=1;
setCenterView();
}
@FXML
public void setCabinTwo() throws IOException {
cabinIndex=2;
setCenterView();
}
@FXML
public void setTabOne() throws IOException {
tabIndex=1;
setCenterView();
}
@FXML
public void setTabTwo() throws IOException {
tabIndex=2;
setCenterView();
}
public int getCabinIndex() {
return cabinIndex;
}
public int getTabIndex() {
return tabIndex;
}
private int tabIndex=0;
private int cabinIndex=1;
public Stage primaryStage;
private BorderPane mainPane;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
this.primaryStage=primaryStage;
primaryStage.setTitle("Test");
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainViewController.class.getResource("MainView.fxml"));
mainPane = loader.load();
setCenterView();
Scene scene = new Scene(mainPane);
primaryStage.setScene(scene);
primaryStage.show();
}
public void setCenterView() throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainViewController.class.getResource("TestView.fxml"));
AnchorPane testPane = loader.load();
TestViewController tvc = loader.<TestViewController>getController();
tvc.changeLabel(getCabinIndex());
tvc.changeIndex(getTabIndex());
mainPane.setCenter(testPane);
}
}
를 다음과 같이 내 TestViewController 보이는 : 내가 잘못 뭐하는 거지
import javafx.fxml.FXML;
import javafx.scene.control.Label;
public class TestViewController {
@FXML
private Label cabinIndex;
@FXML
private Label tabIndex;
public void initialise() {
this.changeLabel(0);
this.changeIndex(0);
}
public void changeLabel(int n) {
cabinIndex.setText("Cabin "+Integer.toString(n));
}
public void changeIndex(int n) {
tabIndex.setText("Tab "+Integer.toString(n));
}
}
?
모든 혼란을 제거하고 더 작은 예제로 제거하십시오. 게다가, 오류 메시지는 매우 도움이 될 것입니다. – rethab
무슨 소리가 나는거야? 내 컴퓨터에 다시 액세스하면 오류 메시지를 게시합니다. –
StackOverflow에 오신 것을 환영합니다. 예제를 게시 할 때 항상 문제를 재현하기에 충분하고 더 이상 재현 할 수없는 [최소, 완전한 예제] (http://stackoverflow.com/help/mcve)를 만들어보십시오. 귀하의 경우에는'TestView.fxml'과'TestViewController'를 완전히 없애고'mainPane'과 버튼 하나만 제외하고'MainViewController'의 모든 것을 제거 할 수 있습니다. 'setCenterPane'의 구현을'mainPane.setCenter (new Label ("Hello"))'로 바꾸면 여전히 같은 스택 추적을 볼 수 있습니다. (이것은 @rethab이 참조하는 "혼란"입니다.) –