Yes, the problem is that your code fails to set a renderer to do that
actual drawing. Your MyMapFrame constructor is implicitly calling the
no-arg constructor of JMapFrame so both the renderer and the map
context will be null at that stage. Later you set the map context but
never set the renderer.

Try adding this to your MyMapFrame constructor...

setRenderer(new StreamingRenderer());

Hope this helps.

Michael


On 7 July 2011 18:36, lexmc <[email protected]> wrote:
> I'm using geotools 2.7.1.
> This is my full code:
>
> public class Main {
>
>        public static void main(String[] args) {
>
>                Properties p = new Properties(System.getProperties());
>                p.put("com.sun.media.jai.disableMediaLib", "true");
>                System.setProperties(p);
>                new MyMapFrame();
>        }
> }
>
> public class MyMapFrame extends JMapFrame{
>
>        private static final long serialVersionUID = 1L;
>
>        public MyMapFrame(){
>                this.setTitle("Viewer");
>                this.setLocation(300, 100);
>                this.setSize(1280, 750);
>                this.enableLayerTable(true);
>                this.enableTool(JMapFrame.Tool.ZOOM, JMapFrame.Tool.PAN,
> JMapFrame.Tool.RESET);
>                this.enableToolBar(true);
>                this.getMapPane();
>                this.getMapContext();
>                this.enableStatusBar(true);
>                this.setVisible(true);
>                this.initComponents();
>                new Map(this);
>        }
> }
>
> public class Map extends MapContext{
>
>        JMapFrame f;
>
>        public Map(JMapFrame frame)
>        {
>                f=frame;
>                f.getContentPane().setLayout(new BorderLayout());
>                f.enableLayerTable(true);
>                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>
>                JMenuBar menubar = new JMenuBar();
>                f.setJMenuBar(menubar);
>
>                JMenu fileMenu = new JMenu("File");
>                menubar.add(fileMenu);
>
>                f.pack();
>
>                fileMenu.add(new SafeAction("Open shapefile...") {
>                        private static final long serialVersionUID = 1L;
>
>                        public void action(ActionEvent e) throws Throwable {
>                                new addMapLayer(f);
>                        }
>                });
>                fileMenu.add(new SafeAction("Add Image Layer...") {
>                        private static final long serialVersionUID = 1L;
>
>                        public void action(ActionEvent e) throws Throwable {
>                                new addImgAndShape(f);
>                        }
>                });
>                fileMenu.add(new SafeAction("Connect to DataBase...") {
>                        private static final long serialVersionUID = 1L;
>
>                        public void action(ActionEvent e) throws Throwable {
>                                new formConnection(f);
>                        }
>                });
>        }
> }
>
> public class addMapLayer implements ActionListener{
>
>        static JMapFrame f;
>        static SimpleFeatureSource featureSource;
>        final JButton btn = new JButton("Zoom");
>        final JButton btn1 = new JButton("Select");
>        static formZoom m;
>        static Selezione sel;
>
>        public addMapLayer(JMapFrame frame) throws IOException
>        {
>                f=frame;
>                File file = JFileDataStoreChooser.showOpenFile("shp", null);
>                if (file == null) {
>                        return;
>                }
>                FileDataStore store = FileDataStoreFinder.getDataStore(file);
>                featureSource = store.getFeatureSource();
>                CachingFeatureSource cache = new 
> CachingFeatureSource(featureSource);
>
>                MapContext map = new DefaultMapContext();
>                sel = new Selezione(f, featureSource);
>                Style style = sel.createDefaultStyle();
>                map.addLayer(cache, style);
>                f.setMapContext(map);
>
>                JToolBar toolBar = f.getToolBar();
>                toolBar.addSeparator();
>                toolBar.add(btn);
>                toolBar.add(btn1);
>
>                btn.addActionListener(this);
>                btn1.addActionListener(this);
>        }
>
>        public void actionPerformed(ActionEvent e) {
>                if(e.getActionCommand()==btn.getActionCommand())
>                {
>                        m=new formZoom(f,featureSource);
>                        m.setVisible(true);
>                }
>                if(e.getActionCommand()==btn1.getActionCommand())
>                {
>                        f.getMapPane().setCursorTool(
>                                        new CursorTool() {
>
>                                                public void 
> onMouseClicked(MapMouseEvent ev) {
>                                                        sel.selectFeatures(ev);
>                                                }
>                                        });
>                }
>        }
> }
>
> --
> View this message in context: 
> http://osgeo-org.1803224.n2.nabble.com/Unable-to-repaint-maplayer-tp6553750p6557568.html
> Sent from the geotools-gt2-users mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> All of the data generated in your IT infrastructure is seriously valuable.
> Why? It contains a definitive record of application performance, security
> threats, fraudulent activity, and more. Splunk takes this data and makes
> sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-d2d-c2
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to