尊敬的开发者,
我正在开发用于桌面的NASA World Wind应用程序。 我试图将JSplitPane放在下面的Panel中显示结果,而上面的一个显示画布分为两部分。左侧组件包含图层列表,右侧组件包含画布。我一直在尝试在左侧组件中插入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
答案 0 :(得分:0)
因此,我能够管理将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);