简体   繁体   English

自动从其他JPanel中的JPanel重绘

[英]automatically redraw from JPanel in other JPanel

I draw two directed graphs in two different JPanels and when i click the button compile (RUN - COMPILARE) i need those graphs to repaint in one JPanel , any suggestions, tips, tutorials for that. 我在两个不同的JPanels绘制了两个有向图,当我单击“编译”(R​​UN-COMPILARE)按钮时,我需要这些图在一个JPanel重新绘制,有关此的任何建议,技巧和教程。 I've searched but no results. 我已经搜索过,但没有结果。

It depends on how you draw them. 这取决于您如何绘制它们。 If you use Shapes just paint them twice in the single (merge panel). 如果使用“ Shapes只需在单个(合并面板)中将它们绘制两次。

You can also override the merge panel's paintComponent() and call in the method with proper transform 您还可以覆盖合并面板的paintComponent()并通过适当的转换调用方法

firstGraphPanel.paintComponent(g);
secondGraphPanel.paintComponent(g);

I think you should override the paintComponent method of that JPanel you want to repaint: 我认为您应该重写要重绘的JPanel的paintComponent方法:

@override
public void paintComponent (Graphics g) {
    // paint your two graphs here.
}

When the button is clicked, call JPanel.repaint(). 单击该按钮后,调用JPanel.repaint()。 For example, 例如,

@Override
public void mouseClicked (MouseEvent me) {
    pnl.repaint();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM