【问题标题】:JTabbedpane in JSplitPaneJSplitPane 中的 JTabbedpane
【发布时间】:2018-04-03 06:24:05
【问题描述】:

尊敬的开发者,

我正在开发一个 NASA World Wind 桌面应用程序。 我试图在下部面板中放置一个 JSplitPane 显示结果,上部显示画布分为两个部分。左侧组件包含图层列表,右侧组件包含画布。我一直在尝试在左侧组件中插入一个 JTabbedPane,以便拥有不同的选项,例如图层列表、SQL 查询列表等等。我无法在左侧面板上添加和查看 JTabbedPane 的框架。

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

感谢所有帮助。

代码块

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);
        }

错误块

"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

【问题讨论】:

    标签: java jtabbedpane jsplitpane


    【解决方案1】:

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

    代码如下,

    代码块

    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);
    

    【讨论】:

      猜你喜欢
      • 2015-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-07
      • 1970-01-01
      • 2012-01-10
      相关资源
      最近更新 更多