1。除了可以在jpanel上画图,那能不能在jscrollpane上画,我试了一下,无显示,为什么?
2。在jpanel里用public void paintComponent(Graphics g)方法可以自动画图,那我如果想在别的方法里对jpanel画怎么办?比如我在jframe里加入一个菜单栏,又加一个jpanel,我想通过对菜单栏的一个菜单点击以后的在actionPerformed方法里画怎么办?请指教,谢谢!
2。在jpanel里用public void paintComponent(Graphics g)方法可以自动画图,那我如果想在别的方法里对jpanel画怎么办?比如我在jframe里加入一个菜单栏,又加一个jpanel,我想通过对菜单栏的一个菜单点击以后的在actionPerformed方法里画怎么办?请指教,谢谢!
2.在paintComponent方法里预设条件选择分支语句 通过响应方法设定相应条件来触发
我是这么做了,但是JScrollPane加上Jpanel画图以后,滚动条不能出现,不知道怎么搞的。
2.在paintComponent方法里预设条件选择分支语句 通过响应方法设定相应条件来触发
这个能不能举个例子,具体点???
menuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
panel.getGraphics.drawLine(10,10,100,100);
}
});
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (paintWhat == 0) {
g.drawString("Now paintWhat is 0", MESSAGE_X, MESSAGE_Y);
}
else if (paintWhat == 1) {
g.drawString("Now paintWhat is 1", MESSAGE_X, MESSAGE_Y);
}
}public void actionPerformed(ActionEvent e) {
panel.setPaintWhat(1);
panel.update(panel.getGraphics());
}