2013-06-02 3 views
1

단일 축을 패널에 그리려면 어떻게해야합니까? 나는 순진하게도 나는 그것이 축을 그리는 방법에 대한 답변 XYChart의 소스를 통해 검색하고 addAll(axis)JavaFX 단일 축 그리기

를하려고하면 그것은 나에게 런타임 예외를 제공

.

편집 :

소스

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.chart.NumberAxis; 
import javafx.scene.layout.StackPane; 
import javafx.scene.paint.Color; 
import javafx.stage.Stage; 

public class TestSingleAxis extends Application { 


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

    @Override 
    public void start(Stage stage) { 

     StackPane root = new StackPane(); 

     root.getChildren().addAll(new NumberAxis(1, 20, 1)); 

     Scene scene = new Scene(root, 1300, 800, Color.WHITESMOKE); 
     stage.setScene(scene); 
     stage.show(); 

    } 

} 

결과

Exception in thread "main" java.lang.RuntimeException: Exception in Application start method 
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:548) 
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:48) 
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:134) 
    at java.lang.Thread.run(Thread.java:722) 
Caused by: java.lang.NullPointerException 
    at javafx.scene.chart.Axis.layoutChildren(Axis.java:744) 
    at javafx.scene.chart.ValueAxis.layoutChildren(ValueAxis.java:359) 
    at javafx.scene.Parent.layout(Parent.java:1014) 
    at javafx.scene.Parent.layout(Parent.java:1022) 
    at javafx.scene.Scene.layoutDirtyRoots(Scene.java:537) 
    at javafx.scene.Scene.doLayoutPass(Scene.java:508) 
    at javafx.scene.Scene.preferredSize(Scene.java:1467) 
    at javafx.scene.Scene.impl_preferredSize(Scene.java:1494) 
    at javafx.stage.Window$10.invalidated(Window.java:720) 
    at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:106) 
    at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:140) 
    at javafx.stage.Window.setShowing(Window.java:783) 
    at javafx.stage.Window.show(Window.java:798) 
    at javafx.stage.Stage.show(Stage.java:242) 
    at guifx.TestSingleAxis.start(TestSingleAxis.java:32) 
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:491) 
    at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:260) 
    at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:223) 
    at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:220) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:220) 
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source) 

Process finished with exit code 1 
+0

예외는 무엇입니까? 코드 탐색 - 올바른 방법입니다! =) –

+0

멋지고 단순하게 정리 했나요? – BAR

답변

1

라인 근처 코드의 일부 버전을 관찰 744 나는 참조 :

if (getSide().equals(Side.LEFT)) { 

그리고이 코드는 말한다 나 :

@Override 
public void start(Stage primaryStage) { 
    System.out.println(new NumberAxis(1, 2, 3).getSide()); 
} 

>>null 

가 도움이됩니까 .. 어쨌든 측면을 지정해야 보인다?

+0

좋은 관찰, 코드가 지금 실행됩니다. 하지만 Side로 설정을 시도하십시오 .BOTTOM은 맨 위에 그립니다. Side.TOP은 맨 아래에 그립니다. 여기에 뭔가 다른 점이 있습니까? – BAR

+0

javadoc에 따라 : ObjectProperty \t 쪽 이 축을 그릴 플롯의면 그렇지 않은 경우 javafx-jira에 문제를 제출하십시오. –