将自定义组件添加到NetBeans GUI构建器! (世界风)

时间:2011-06-25 23:59:38

标签: java swing user-interface netbeans worldwind

好的,我正在尝试将NASA的World Wind globe添加到NetBeans GUI builder创建的GUI窗口中。我的示例代码实例化了自己的窗口,GUI构建器希望我不要编辑滑动它所需的区域:)我自己编写,但这是NetBeans平台应用程序的一部分,包含代码和注释我没准备好要处理。我不知道如何做到这一点。以下是我在窗口中想要的示例代码:

public class WorldWindTest {

public static void main(String[] args) {

    //create a WorldWind main object
    WorldWindowGLCanvas worldWindCanvas = new WorldWindowGLCanvas();
    worldWindCanvas.setModel(new BasicModel());
            Position myPoint = Position.fromDegrees(31.12, -88.64, 35000);


    //build Java swing interface
    JFrame frame = new JFrame("World Wind");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(worldWindCanvas);
    frame.setSize(800,600);
    frame.setVisible(true);

    //create some "Position" to build a polyline
    LinkedList<Position> list = new LinkedList<Position>();

//          list.add(Position.fromDegrees(i,0.0,i*20000));
    }

            list.add(Position.fromDegrees(30.12, -85.64, 35000));
            list.add(Position.fromDegrees(31.12, -88.64, 35000));


    //create "Polyline" with list of "Position" and set color / thickness
    Polyline polyline = new Polyline(list);
    polyline.setColor(Color.RED);
    polyline.setLineWidth(3.0);

    //create a layer and add Polyline
    RenderableLayer layer = new RenderableLayer();
    layer.addRenderable(polyline);
    //add layer to WorldWind
    worldWindCanvas.getModel().getLayers().add(layer);
}
}   

2 个答案:

答案 0 :(得分:4)

为了放大我的评论,我想你可以创建一个类,比如叫做SetUpWorldWindowGLCanvas,然后在其中初始化并设置你的WorldWindowGLCanvas对象,然后给它一个公共的getter方法,让你获得设置WorldWindowGLCanvas对象。即,

public class SetUpWorldWindowGLCanvas {

    WorldWindowGLCanvas worldWindCanvas = new WorldWindowGLCanvas();

    public SetUpWorldWindowGLCanvas() {
        worldWindCanvas.setModel(new BasicModel());
        Position myPoint = Position.fromDegrees(31.12, -88.64, 35000);

        // ... etc
    }

    public WorldWindowGLCanvas getWwGlCanvas() {
        return worldWindCanvas;
    }
}

然后将此BorderLayout.CENTER放置在GUI构建器中创建的JPanel中,并使用BorderLayout作为其布局管理器。

答案 1 :(得分:3)

不要在整个应用程序中使用GUI编辑器,而是仅使用几个最受益于它的容器,例如:困难的布局。然后,您的WorldWindowGLCanvas可以正常添加到top-level container。在此example中,WorldWindowGLCanvas会与NewJPanel一起显示:

JFrame f = new JFrame();
f.setLayout)new GridLayout(1, 0);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(worldWindCanvas);
f.add(new NewJPanel());
f.pack();
f.setVisible(true);