-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.5
-
sparc
-
solaris_2.5.1
Name: rk38400 Date: 04/13/98
#Description
Clipping in a JScrollPane failed. If we draw into
a component which is in the JScrollPane and
we use getGraphics to get the graphic context
the JScrollPane don't clip the parts away
which are not seen.
I am not sure if this is a bug, or the user
have to make sure to get the "right" context
using getViewport().getGraphics() ?
The Java Code examples gives you an idea what
I mean:
#JAVA-Code
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import java.beans.*;
public class bug2 extends JFrame implements MouseListener, MouseMotionListener, WindowListener {
MyComp comp;
public bug2(){
addMouseListener(this);
addMouseMotionListener(this);
JPanel hugo = new JPanel();
hugo.setPreferredSize(new Dimension(300,300));
hugo.setBackground(Color.green);
comp = new MyComp();
comp.setPreferredSize(new Dimension(400,400));
JScrollPane scroll = new JScrollPane();
scroll.setPreferredSize(new Dimension(300,300));
JPanel fritz = new JPanel();
fritz.add(scroll);
fritz.setPreferredSize(new Dimension(300,300));
fritz.setBackground(Color.yellow);
getContentPane().setLayout(new GridBagLayout());
getContentPane().add(scroll);
getContentPane().add(hugo);
scroll.getViewport().add(comp);
pack();
}
public void mouseReleased(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {
System.out.println("Mouse clicked");
comp.drawLine();
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseDragged(MouseEvent e) { }
public void mouseMoved(MouseEvent e) {}
public void mousePressed(MouseEvent e){}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
public void windowClosed(WindowEvent e) {
System.exit(0);
}
public void windowClosing(WindowEvent e) {
System.exit(0);
};
public void windowActivated(WindowEvent e) {}
public static void main(String[] args) {
bug2 f = new bug2();
f.pack();
f.show();
}
}
class MyComp extends JComponent {
public MyComp(){
setSize(100,100);
setPreferredSize(new Dimension(200,200));
}
public void paint(Graphics g){
g.setColor(Color.red);
g.drawRoundRect(10,10,100,200,30,30);
}
public void drawLine(){
Graphics g = getGraphics();
g.setColor(Color.red);
g.drawLine(0,0,600,300);
}
}
(Review ID: 26561)
======================================================================
- duplicates
-
JDK-4124260 Painting problems w/ JScrollPane when done other than in paint(Graphics) functi
-
- Closed
-