java - JMapFrame 和 GUI [Java]

标签 java swing jpanel grid-layout jmap

好的,大家好,首先我展示一下我有什么:

enter image description here

我有这个代码:

public static void main(String[] arg) throws IOException {

    map = new DefaultMapContext();
    map.setTitle("Visualizador UD - Geotools");

    mapFrame = new JMapFrame(map);
    mapFrame.enableToolBar(true);
    mapFrame.enableStatusBar(true);//Herramientas abajo

    JToolBar toolBar = new JToolBar();

    eliminar = new JButton("Eliminar capas");
    adicionar = new JButton("Adicionar capas");
    consultar = new JButton("Consultar");

    mapFrame.getToolBar().add(adicionar);
    mapFrame.getToolBar().add(eliminar);
    mapFrame.getToolBar().add(consultar);

    listaLayers = new List();

    for (int i = 0; i < files.length; i++) {
        listaLayers.add(files[i].getName());
    }

    menu();
    mapFrame.add(listaLayers, BorderLayout.WEST);
    mapFrame.add(toolBar, BorderLayout.NORTH);

    mapFrame.setSize(800, 600);
    mapFrame.setVisible(true);
}

好吧,我的目标是类似的,同一个组织:

enter image description here

但我不知道该怎么做,这让我有点困惑,问题是图层,我不能把它放在 map 的左边......我希望你可以帮助我以更好的方式编写我的代码。

最佳答案

我想这或许能解决您的问题。

尝试

// this will get you left pane with the layers added.
frame.enableLayerTable(true); 

您也可以直接使用下面的代码直接完成您的工作。

    JMapFrame frame;
    MapContent map;
    frame = new JMapFrame(map);
    frame.enableLayerTable(true);
    frame.setSize(800, 600);
    frame.enableStatusBar(true);        
    frame.enableToolBar(true);                
    JMenuBar menuBar = new JMenuBar();                          
    frame.setJMenuBar(menuBar);

添加光栅和形状文件使用: public void addshape(File shpFile) 抛出异常{

    FileDataStore dataStore = FileDataStoreFinder.getDataStore(shpFile);
    SimpleFeatureSource shapefileSource = dataStore.getFeatureSource();       
    Style shpStyle = SLD.createPolygonStyle(Color.RED, null, 0.0f);
    Layer shpLayer = new FeatureLayer(shapefileSource, shpStyle);       
    map.addLayer(shpLayer);
    show();    
 }
 public void addraster(File rasterFile) throws Exception {         
    AbstractGridFormat format = GridFormatFinder.findFormat( rasterFile );
    reader = format.getReader(rasterFile);     
    Style rasterStyle = createGreyscaleStyle(1);      
    Layer rasterLayer = new GridReaderLayer(reader, rasterStyle);
    map.addLayer(rasterLayer);        
    show();
    }

关于java - JMapFrame 和 GUI [Java],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13892908/

相关文章:

java - 我的 jsp 页面未使用结果集 rs=st.executeQuery(); 进行验证

java - 具有不同轴的嵌套 BoxLayout

java - 按下 jtoolbar 按钮时在不同的 JPanel 之间切换

java - 如何每帧多次重绘 JFrame 及其组件?

java - Java在一定时间内创建多个线程

Java内存清理

java - 重新打包 Spring Boot 应用程序

java - 任务托盘通知气球事件?

java - EventQueue.invokeLater 与 start() 线程相比有何作用?

java - jPanel 的背景图像不工作