受人尊敬的开发人员,
我正在开发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)Javajdk1.7.0_03binjava" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2017.3.4libidea_rt.jar=55088:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2017.3.4bin" -Dfile.encoding=UTF-8 -classpath "C:Program Files (x86)Javajdk1.7.0_03jrelibcharsets.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibdeploy.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibextdnsns.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibextlocaledata.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibextsunec.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibextsunjce_provider.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibextsunmscapi.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibextsunpkcs11.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibextzipfs.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibjavaws.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibjce.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibjsse.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibmanagement-agent.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibplugin.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibresources.jar;C:Program Files (x86)Javajdk1.7.0_03jrelibrt.jar;D:NasaWorldWindclasses;D:NasaWorldWindjogl-all.jar;D:NasaWorldWindgluegen-rt.jar;D:NasaWorldWindgdal.jar;D:DOWNLOADSpostgresql-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
所以,我能够在JSPlitpane的左组件中管理JTABBEDPANE。
代码如下,
代码块
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);