Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

This code is not working as needed. I need just to make a window with addlayer button.

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
//import org.geotools.renderer.GTRenderer;
//import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.JMapPane;
import org.geotools.swing.data.JFileDataStoreChooser;

public class App2 {

public static void showMap(final MapContent map) throws IOException {

       final JMapPane mapPane = new JMapPane(map);
      // mapPane.setMapArea(map.getLayerBounds());

       JFrame frame = new JFrame("cis");
       frame.setLayout(new BorderLayout());
       frame.add(mapPane, BorderLayout.CENTER);
       JPanel buttons = new JPanel();

      /* JButton zoomInButton = new JButton("Zoom In");
       zoomInButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {  mapPane.repaint(); } });

       JButton zoomOutButton = new JButton("Zoom Out");
       zoomOutButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {  mapPane.repaint();  } });

       JButton pamButton = new JButton("Move");
       pamButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {   mapPane.repaint(); } });
       JButton addLayer = new JButton("Add Layer");
       addLayer.addActionListener(new ActionListener()  { public void actionPerformed(ActionEvent e) {
               File file = JFileDataStoreChooser.showOpenFile("shp", null);
            if (file == null) {
            FileDataStore store = FileDataStoreFinder.getDataStore(file);
            SimpleFeatureSource featureSource = store.getFeatureSource();
            Style style = SLD.createSimpleStyle(featureSource.getSchema());
            Layer layer = new FeatureLayer(featureSource, style);
             }catch(IOException f){}
        } });

       frame.add(buttons, BorderLayout.NORTH);
       frame.setSize(600, 400);

    public static void main(String s){

           MapContent map = new MapContent();
            map.setTitle("Climate information system");

share|improve this question
how is it working? –  iant Jul 16 '13 at 14:52

1 Answer 1


This will call showMap method of the JMapFrame class or geotools but not your App2 class showMap method please correct it and try again

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.