2017-11-01 2 views
1

저는 JavaFX를 처음 사용하기 때문에 menubar가없는 앵커 패널 두 개를 전환해야하지만 앵커 패널 자체에 가입 버튼이있어서 등록 양식 양식으로 전환해야합니다. 로그인 양식 작성기 .FXML 파일을 생성하려면,두 개의 앵커 패널 간 전환

내 질문은 간단한 방법으로 이것을하는 방법입니까? javafx.fxml.FXMLLoader에서 java.lang.reflect.InvocationTargetException : loginForm with signup button

enter image description here

ERRRO는 java.lang.RuntimeException가 "자바 FX 애플리케이션 쓰레드"글

예외 $ MethodHandler.invoke (FXMLLoader.java:1774) at javafx.fxml.FXMLLoader $ ControllerMethodEventHandler.handle (FXMLLoader.java:1657) at com.sun.javafx.event에서 51,515,com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent (EventHandlerManager.java:238)에서 (CompositeEventHandler.java:86) com.sun.javafx.event.BasicEventDispatcher.dispatchEvent에서 .EventHandlerManager.dispatchBubblingEvent com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent (CompositeEventDispatcher.java:59)에서 (EventHandlerManager.java:191) (BasicEventDispatcher.java : 58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent (EventDispatchChainImpl.java:114) at com.sun.javaf com.sun.javafx.event.BasicEventDispatcher.dispatchEvent에서 x.event.BasicEventDispatcher.dispatchEvent com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent (EventDispatchChainImpl.java:114)에서 (BasicEventDispatcher.java:56) (COM에서 com.sun.javafx.event.EventUtil.fireEventImpl (EventUtil.java:74) 에서 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent (EventDispatchChainImpl.java:114) 에서 BasicEventDispatcher.java:56) .sun.javafx.event.EventUtil.fireEvent (EventUtil.java:49) at javafx.event.Event.fireEvent (Event.java:198) at javafx.scene.Node.fireEvent (Node.java:8413) at javafx.scene.control.Button.fire (Button.java:185) at,451,515, com.sun.javafx.scene.control.skin.BehaviorSkinBase $의 1.handle에서 com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased (ButtonBehavior.java:182) (BehaviorSkinBase.java:96) com.sun.javafx.event.CompositeEventHandler $ NormalEventHandlerRecord.handleBubblingEvent (CompositeEventHandler.java:218) 에서 com.sun.javafx.scene.control.skin.BehaviorSkinBase $의 1.handle (BehaviorSkinBase.java:89) 에서의에서 com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent (EventHandlerManager.java:238)에서 (CompositeEventHandler.java:80) com.sun.javafx.event에서 0 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent (CompositeEventDispatcher.java:59)에서 (EventHandlerManager.java:191) .BasicEventDispatcher.dispatchEvent (BasicEventDispatcher.자바 : 58) com.sun.javafx.event.BasicEventDispatcher.dispatchEvent (BasicEventDispatcher.java:56) 에서 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent (EventDispatchChainImpl.java:114) 에서 에서 COM com.sun.javafx.event.EventDispatchChainImpl에서 .sun.javafx.event.EventDispatchChainImpl.dispatchEvent com.sun.javafx.event.BasicEventDispatcher.dispatchEvent (BasicEventDispatcher.java:56)에서 (EventDispatchChainImpl.java:114) .dispatchEvent (EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl (EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent (EventUtil.java:54) at javafx.event.Event.fireEvent (Event.java:198) at javafx.scene.Scene $ MouseHandler.process (Scene.java:3757) at javafx.scene.Scene $ MouseHandler.access $ 1500 (Scene.java : 3485) at javafx.scene.Scene.impl_processMouseEvent (Scene.java:1762) at javafx.scene.Scene $ ScenePeerListener.mouseEvent (Scene.java:2494) at com.sun.javafx.tk.quantum.GlassViewEventHandler $ 에서 java.security.AccessController.doPrivileged (기본 방법)에서 com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run (GlassViewEventHandler.java:294) 에서 MouseEventNotification.run (GlassViewEventHandler.java:380) com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda $ handleMouseEvent $ 354 (GlassViewEventHandler.jav A : 416) com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent에서 (QuantumToolkit.java:389) 에서 (GlassViewEventHandler.java:415) com.sun.glass.ui.View.handleMouseEvent (View.java:555)에서 com.sun.glass.ui.View.notifyMouse (View.java:937) com.sun.glass.ui. win.WinApplication._runLoop (네이티브 메소드) at com.sun.glass.ui.win.WinApplication.lambda $ null $ 148 (WinApplication.java:191) at java.lang.Thread.run (알 수없는 소스) 원인 : 에서의 java.lang.reflect.InvocationTargetException 에서의 sun.reflect.NativeMethodAccessorImpl.invoke0 (네이티브 메소드) su sun.reflect.misc.Trampoline.invoke에서 java.lang.reflect.Method.invoke에서 sun.reflect.DelegatingMethodAccessorImpl.invoke (알 소스) (알 소스)에 n.reflect.NativeMethodAccessorImpl.invoke (알 소스) sun.reflect에서 java.lang.reflect.Method.invoke (알 소스)에 sun.reflect.DelegatingMethodAccessorImpl.invoke (알 소스)에 sun.reflect.GeneratedMethodAccessor1.invoke (알 소스)에서 (알 소스) .mspc.mlx.loaded (FXMLLoader.java:1771) ... 더 많은 원인 : java.lang.IllegalStateException : 위치가 으로 설정되지 않았습니다. javafx.fxml.FXMLLoader.loadImpl (FXMLLoader.java:2434) 에서 javafx.fxml.FXMLLoader.load (FXMLLoader.java:2409) localmart.view.AuthController.Register (AuthController.java:22) ...에서 58 더

Main.java

package localmart.view; 
import java.io.IOException; 

import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Scene; 
import javafx.scene.layout.AnchorPane; 
import javafx.stage.Stage; 

public class Main extends Application { 
    private Stage primaryStage; 
    private AnchorPane mainLayout; 

    @Override 
    public void start(Stage primaryStage) { 
     this.primaryStage = primaryStage; 
     this.primaryStage.setTitle("Local Mart"); 
     showMainView(); 

    } 

    private void showMainView() { 
     FXMLLoader loader = new FXMLLoader(); 
     loader.setLocation(Main.class.getResource("view/login.fxml")); // login 
                     // form 
     try { 
      mainLayout = loader.load(); 
      Scene scene = new Scene(mainLayout); 
      primaryStage.setScene(scene); 
      primaryStage.show(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 

컨트롤러.자바

package localmart.view; 

    import java.io.IOException; 

import javafx.fxml.FXML; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.control.TextField; 
import javafx.scene.layout.AnchorPane; 
import javafx.scene.layout.Pane; 

public class AuthController { 
    @FXML AnchorPane anchorPane; 

@FXML 
private void RegisterStage() throws IOException { 
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("reg.fxml")); 
    Pane registerPane = (Pane) fxmlLoader.load(); 
    try { 
     anchorPane.getChildren().clear(); 
     anchorPane.getChildren().add(registerPane); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 
} 
내가 registerform을 전환 할 필요가 main.java와 클릭 가입 버튼 양식을 등록로드하는 방법

내 질문에

내가 컨트롤러의 OnAction는, FX 세트 : ID가

을 login.fxml하기
+0

fxml 파일을 공유하고 전환하여 무엇을 의미합니까? 가입 앵커판을 숨기고 registerform을 표시 ??? 아니면 둘 다 보입니까? –

+0

두 개의 fxml 파일을 디자인했습니다. 하나는 로그인 양식과 다른 등록 양식입니다 ... 로그인 양식 단계 (창)에있는 가입 단추를 클릭하면 등록 양식 창이 열립니다. –

+0

그래서 실제로 다른 fxml 파일을로드하려고합니다. 같은 장면 맞지? 현재 장면에서 같은 fxml을로드하는 버튼 액션에서 동일한 메소드'showSignUp()'을 호출하고 있습니다. 그래서 내가 말했던 것을 시도한다면, 먼저 로그인 fxml을로드하고 버튼 액션 –

답변

1

AnchorPanelogin.fxml에 있어야하며 다른 모든 요소의 컨테이너가 될 것이며 anchorPaneid, 그 중 Anchorpane (사용자가 선택할 수 있음)을 설정합니다. 그 일을 한 후, 당신은 단지로드 할 fxml 원하는에 의해 reg.fxml를 교체 컨트롤러 클래스

@FXML AnchorPane anchorPane; 

@FXML 
private void RegisterStage() throws IOException { 
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("reg.fxml")); 
    Pane registerPane = (Pane) fxmlLoader.load(); 
    try { 
     anchorPane.getChildren().clear(); 
     anchorPane.getChildren().add(registerPane); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

에서이 코드 섹션을 추가해야합니다.

+0

나는 내 질문을 업데이트했습니다 .. 정확히 내가 말한 것을 바꾸면 오류가 발생했습니다 –

+0

위 질문에 폴더 구조를 넣었습니다 –

+0

가입 버튼을 클릭하면 충돌이 발생합니까? 프레스?? 그리고 동일한 패키지에있는 컨트롤러 클래스와 fxml을 사용하려면'FXMLLoader fxmlLoader = new FXMLLoader (getClass(). getResource ("Register.fxml")); ' –