在子 jpanel 上重新绘制
好吧,假设我在另一个 jpanel 中有一个 JPanel“控件”和 jpanel“graphPanel”,
public class outer extends JPanel implements ActionListener{
private JPanel controls,graphPanel;
private JButton doAction
public outer(){
JPanel controls = new JPanel();
JButton doAction = new JButton("Do stuff");
doAction.addActionListener(this);
controls.add(doAction);
JPanel graphPanel = new JPanel();
this.add(controls);
this.add(graphPanel);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==doAction){
//How do I fire paintComponent of controls JPanel on this click
}
单击按钮后如何重新绘制“graphPanel”
Ok say I have a JPanel "controls" and jpanel "graphPanel" within another jpanel
public class outer extends JPanel implements ActionListener{
private JPanel controls,graphPanel;
private JButton doAction
public outer(){
JPanel controls = new JPanel();
JButton doAction = new JButton("Do stuff");
doAction.addActionListener(this);
controls.add(doAction);
JPanel graphPanel = new JPanel();
this.add(controls);
this.add(graphPanel);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==doAction){
//How do I fire paintComponent of controls JPanel on this click
}
How do i make "graphPanel" repaint after my button is clicked
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
doAction 和 graphPanel 声明了两次 - 一次在类级别,然后在方法中再次声明:
在方法中删除声明,并使它们成为简单的赋值,如下所示:
这样做,附加的重绘代码将不会抛出 NPE
The doAction and graphPanel are declared twice - once at the class level, then again in the method:
In the method remove the declaration, and make them simple assignments, like this:
Do that and the additional repaint code won't throw a NPE