Панель диспетчера слоёв WorldWind пуста
Я занимаюсь разработкой приложения WorldWind и хочу повторно использовать пример класса LayerAndElevationManagerPanel в своем собственном приложении. Я пытаюсь поместить его в диалоговое окно, которое пользователь может вызвать по требованию, однако, когда диалоговое окно отображается, панель прокрутки для панели пуста. Можно ли использовать этот пример повторно?
Вот пример кода от WorldWind
/*
* Copyright (C) 2013 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
package gov.nasa.worldwindx.examples.layermanager;
import gov.nasa.worldwind.WorldWindow;
import javax.swing.*;
import java.awt.*;
/**
* Combines the layer manager and elevation model manager in a single frame.
*
* @author tag
* @version $Id$
*/
public class LayerAndElevationManagerPanel extends JPanel
{
protected LayerManagerPanel layerManagerPanel;
protected ElevationModelManagerPanel elevationModelManagerPanel;
public LayerAndElevationManagerPanel(WorldWindow wwd)
{
super(new BorderLayout(10, 10));
this.add(this.layerManagerPanel = new LayerManagerPanel(wwd), BorderLayout.CENTER);
this.add(this.elevationModelManagerPanel = new ElevationModelManagerPanel(wwd), BorderLayout.SOUTH);
}
public void updateLayers(WorldWindow wwd)
{
this.layerManagerPanel.update(wwd);
}
public void updateElevations(WorldWindow wwd)
{
this.elevationModelManagerPanel.update(wwd);
}
public void update(WorldWindow wwd)
{
this.updateLayers(wwd);
this.updateElevations(wwd);
}
}
Вот мой код
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwindx.examples.layermanager.LayerAndElevationManagerPanel;
public class LayerDialog extends JDialog
{
private final JPanel contentPanel = new JPanel();
/**
* Create the dialog.
*/
public LayerDialog(WorldWindow wwd)
{
setTitle("Layer Manager");
setBounds(100, 100, 386, 360);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportBorder(null);
scrollPane.add(new LayerAndElevationManagerPanel(wwd));
GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
gl_contentPanel.setHorizontalGroup(
gl_contentPanel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPanel.createSequentialGroup()
.addContainerGap()
.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 344, GroupLayout.PREFERRED_SIZE)
.addContainerGap(6, Short.MAX_VALUE))
);
gl_contentPanel.setVerticalGroup(
gl_contentPanel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPanel.createSequentialGroup()
.addContainerGap()
.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
.addContainerGap())
);
contentPanel.setLayout(gl_contentPanel);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
}
}
Вот выдержка из MainWindow
public MainWindow(App a)
{
WorldWindowGLCanvas wwd = new WorldWindowGLCanvas();
JMenuItem mntmLayers = new JMenuItem("Layers");
mntmLayers.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
try
{
LayerDialog dialog = new LayerDialog(wwd);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
});
}