繁体   English   中英

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

[英]Adding a custom component to NetBeans GUI builder! (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);
}
}   

为了放大我的评论,我想你可以创建一个类,比如叫做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作为其布局管理器。

而不是使用GUI编辑器为您的整个应用程序,限制它只使用最有利于它的几个容器,例如困难的布局。 然后,您的WorldWindowGLCanvas可以正常添加到您的顶级容器中 在此示例中WorldWindowGLCanvas将与NewJPanel一起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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM