首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JTabbedpane in JSplitPane

JTabbedpane in JSplitPane
EN

Stack Overflow用户
提问于 2018-04-03 06:24:05
回答 1查看 135关注 0票数 0

尊敬的开发人员,

我正在开发一个美国宇航局世界风的桌面应用程序。我尝试将一个JSplitPane放在较低的面板中显示结果,而上面的面板显示画布在两个部分。左侧组件包含层列表,右边组件包含画布。我一直试图在左侧组件中插入一个JTabbedPane,以便有不同的选项,如层列表、SQL查询列表等等。我无法添加和查看左侧面板上的JTabbedPane框架。

我附上我的代码以供参考。

所有的帮助都是感激的。

码块

代码语言:javascript
复制
public AppFrame()
        {
            /*------------------------------------INITIALIZATION OF THE MAIN FRAME------------------------------------*/
            this.initialize(false, true, false);

            /*---------------------------------------SPLIT PANE AND PANEL CODE---------------------------------------*/
            // Create a horizontal split pane containing the layer panel and the WorldWindow panel.
            JSplitPane horizontalSplitPane = new JSplitPane();
            horizontalSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
            JTabbedPane tp=new JTabbedPane();
            horizontalSplitPane.setLeftComponent(tp);
            horizontalSplitPane.setRightComponent(wwjPanel);
            horizontalSplitPane.setOneTouchExpandable(true);
            horizontalSplitPane.setContinuousLayout(true);// prevents the pane's being obscured when expanding right

            // Create a panel for the bottom component of a vertical split-pane.
            JPanel bottomPanel = new JPanel(new BorderLayout());
            JLabel label = new JLabel("Bottom Panel");
            label.setBorder(new EmptyBorder(10, 10, 10, 10));
            label.setHorizontalAlignment(SwingConstants.CENTER);
            bottomPanel.add(label, BorderLayout.CENTER);

            // Create a vertical split-pane containing the horizontal split plane and the button panel.
            JSplitPane verticalSplitPane = new JSplitPane();
            verticalSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
            verticalSplitPane.setTopComponent(horizontalSplitPane);
            verticalSplitPane.setBottomComponent(bottomPanel);
            verticalSplitPane.setOneTouchExpandable(true);
            verticalSplitPane.setContinuousLayout(true);
            verticalSplitPane.setResizeWeight(1);

            // Add the vertical split-pane to the frame.
            this.getContentPane().add(verticalSplitPane, BorderLayout.CENTER);
            this.pack();

            // Center the application on the screen.
            Dimension prefSize = this.getPreferredSize();
            Dimension parentSize;
            java.awt.Point parentLocation = new java.awt.Point(0, 0);
            parentSize = Toolkit.getDefaultToolkit().getScreenSize();
            int x = parentLocation.x + (parentSize.width - prefSize.width) / 2;
            int y = parentLocation.y + (parentSize.height - prefSize.height) / 2;
            this.setLocation(x, y);
            this.setResizable(true);

            /*-------------------------------------------PATH CREATION CODE-------------------------------------------*/
            // Add a dragger to enable shape dragging
            this.getWwd().addSelectListener(new BasicDragger(this.getWwd()));

            // Create and set an attribute bundle.
            ShapeAttributes attrs = new BasicShapeAttributes();
            attrs.setOutlineMaterial(new Material(WWUtil.makeRandomColor(null)));
            attrs.setOutlineWidth(2d);

            ArrayList<Position> pathPositions = new ArrayList<Position>();
            pathPositions.add(Position.fromDegrees(26, 75, 1e4));
            pathPositions.add(Position.fromDegrees(20, 80, 1e4));
            Path path = new Path(pathPositions);
            path.setAttributes(attrs);
            path.setVisible(true);
            path.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND);
            path.setPathType(AVKey.GREAT_CIRCLE);
            RenderableLayer propertiesLayer = new RenderableLayer();
            propertiesLayer.addRenderable(path);


            /*--------------------------------------------TABBED PANE CODE--------------------------------------------*/
            JTextArea ta = new JTextArea();
            horizontalSplitPane.add(ta);
//            JPanel p2=new JPanel();
//            JPanel p3=new JPanel();

            tp.setBounds(50,50,200,200);
            tp.add("Layers",layerPanel);
//            tp.add("SQL",p2);
//            tp.add("help",p3);
            horizontalSplitPane.add(tp);
            tp.setSize(400,400);
            tp.setLayout(null);
            tp.setVisible(true);

            // Add the layer to the model.
            insertBeforeCompass(getWwd(), propertiesLayer);

            List<String> markers = new ArrayList<String>(1);
            markers.add(String.valueOf(new BasicMarker(Position.fromDegrees(90, 0), new BasicMarkerAttributes())));
            MarkerLayer markerLayer = new MarkerLayer();
//            markerLayer.setMarkers(markers);
            insertBeforeCompass(getWwd(), markerLayer);
        }

错误块

代码语言:javascript
复制
"C:\Program Files (x86)\Java\jdk1.7.0_03\bin\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3.4\lib\idea_rt.jar=55088:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\charsets.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\deploy.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\ext\dnsns.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\ext\localedata.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\ext\sunec.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\ext\sunjce_provider.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\ext\sunmscapi.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\ext\sunpkcs11.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\ext\zipfs.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\javaws.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\jce.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\jsse.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\management-agent.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\plugin.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\resources.jar;C:\Program Files (x86)\Java\jdk1.7.0_03\jre\lib\rt.jar;D:\NasaWorldWind\classes;D:\NasaWorldWind\jogl-all.jar;D:\NasaWorldWind\gluegen-rt.jar;D:\NasaWorldWind\gdal.jar;D:\DOWNLOADS\postgresql-42.2.1.jre7.jar" avr_dbpostgisapp.ApplicationTemplateTest
java.lang.InstantiationException: avr_dbpostgisapp.ApplicationTemplateTest$AppFrame
    at java.lang.Class.newInstance0(Class.java:357)
    at java.lang.Class.newInstance(Class.java:325)
    at avr_dbpostgisapp.ApplicationTemplateTest.start(ApplicationTemplateTest.java:410)
    at avr_dbpostgisapp.ApplicationTemplateTest.main(ApplicationTemplateTest.java:586)
Exception in thread "main" java.lang.NullPointerException
    at avr_dbpostgisapp.ApplicationTemplateTest.connstart(ApplicationTemplateTest.java:502)
    at avr_dbpostgisapp.ApplicationTemplateTest.main(ApplicationTemplateTest.java:588)

Process finished with exit code 1
EN

回答 1

Stack Overflow用户

发布于 2018-04-03 07:06:03

因此,我能够管理JTabbedPane添加到JSplitPane的左边组件。

代码如下,

码块

代码语言:javascript
复制
JSplitPane horizontalSplitPane = new JSplitPane();
            horizontalSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
            JTextArea ta = new JTextArea(200, 200);
            JPanel p1 = new JPanel();
            JPanel p2 = new JPanel();
            p1.add(ta);
            p2.add(ta);
            JTabbedPane tp = new JTabbedPane();
            tp.add("Layers",layerPanel);
            tp.add("SQL",p2);
            horizontalSplitPane.setLeftComponent(tp);
            horizontalSplitPane.setRightComponent(wwjPanel);
            horizontalSplitPane.setOneTouchExpandable(true);
            horizontalSplitPane.setContinuousLayout(true);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49623508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档