Neviem ci je tam metoda na vymedzenie a ak inc nenajdes mozes skusit nieco na tento sposob. Ze si vytvoris buffer a kreslis do neho:
Point selectionPosition = ...;
BufferedImage backBuffer = ...;
BufferedImage selctionBuffer = ...; // Ma presne tu istu velkost ako oblast
public Rectangle makeSelection(int x, int y, int w, int h){
selectionPosition = new Point(x,y);
selectionBuffer = backBuffer.getSubimage(x,y,w,h);
}
public void paintComponent(Graphics g){
render()
g.drawImage(backBuffer,0,0,null);
g.disopose();
}
public void render(){
Graphics g = backBuffer.getGraphics();
// kod toho co sa kresli v komponente
// pripadne sa to vobec nemusi prekreslovat ak netreba
if(selectionBuffer!=null){
renderSelection();
g.drawImage(slectionBuffer, selectionPosition.x, selectionPosition.y,null);
}
g.dispose();
}
public void renderSelection(){
int x = recalculate();
Graphics g = selectionBuffer.getGraphics();
// kreslis do vybranej oblasti.
g.dispose();
}
Aha, az teraz som si vsimol, ze si si vobec nevytvoril referenciu na ten novo vytvoreny object a stale pouzivas iba ten povodny, ktory nieje vymedzeny. Tu je riesenie, ktore mozno bude fungovat:
public void paint(Graphics g){
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
super.paint(g);
Graphics slectionGraphics = g.create(203, 80, screenSize.width-203,screenSize.height-80);
// Teraz kreslis do selectionGraphics.
// slectionGraphics.drawLine(0,10,100,10);
...
}