java - JScrollPane holding a JPanel is buggy -


recently started making map editor game , came across couple of issues i've kind of have fixed. current problem right have jframe (main interface). within jframe have jscrollpane holds client(a jpanel). since can't post picture post link of image. image of gui: http://i.imgur.com/ypnalys.png

this add client(jpanel) jscrollpane.

//======== mainscrollpane ========         {             client.setpreferredsize(client.getsize());             mainscrollpane.setpreferredsize(client.getsize());             mainscrollpane.setviewportview(client);             mainscrollpane.add(client); 

this client.java|the mapeditor class little large post here feel free ask snippets or anymore information.

import java.awt.graphics; import java.awt.graphics2d; import java.awt.event.mouseevent; import java.awt.event.mouselistener; import java.awt.event.mousemotionlistener;  import javax.swing.jpanel;  public class client extends jpanel implements runnable, mouselistener, mousemotionlistener {      private static final long serialversionuid = 1l;     private thread animationthread;     protected map map;     private tile tile;     public int mx, my;      public client() {         init();         setvisible(true);         setfocusable(true);         animationthread = new thread(this);         animationthread.start();     }      public void init() {         addmouselistener(this);         addmousemotionlistener(this);         imagehandler.loadimages();         map = new map();         setsize(1000, 500);     }      public void run() {         while (animationthread != null) {             repaint();             try {                 thread.sleep(4);             } catch (interruptedexception e) {                 e.printstacktrace();             }         }     }      public void paint(graphics g) {         graphics2d gg = (graphics2d) g;         map.drawcurrentmap(gg);      }      @override     public void mouseclicked(final mouseevent e) {         //final point p = e.getpoint();         //final int x = p.x / 25;         //final int y = p.y / 25;         //map.gettileat(x, y).setgraphicid(mapeditor.id);         //map.gettileat(x, y).setblocked(true);         map.gettiles().set(map.gettileindex(mx, my), new tile(mx, my, true, mapeditor.id));         system.out.println(map.gettiles().get(map.gettileindex(mx, my)).tostring());      }      @override     public void mouseentered(mouseevent arg0) {         // todo auto-generated method stub      }      @override     public void mouseexited(mouseevent arg0) {         // todo auto-generated method stub      }      @override     public void mousepressed(mouseevent e) {;      }      @override     public void mousereleased(mouseevent arg0) {         // todo auto-generated method stub      }      @override     public void mousedragged(mouseevent e) {      }      @override     public void mousemoved(mouseevent e) {         mx = e.getx()/25;         = e.gety()/25;     } } 

this has nothing scroll pane, how you've done custom painting...

basically, this...

public void paint(graphics g) {     graphics2d gg = (graphics2d) g;     map.drawcurrentmap(gg); } 

is breaking paint chain requirements. graphics context shared resource, meaning painting within given paint cycle shares same graphics contents.

painting complex chain of methods is, you've discovered, easy break.

instead, should override paintcomponent , perform custom painting there, making sure call super.paintcomponent first

take @ performing custom painting , painting in awt , swing more details


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -