简体   繁体   中英

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. 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).

You can also override the merge panel's paintComponent() and call in the method with proper transform

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

I think you should override the paintComponent method of that JPanel you want to repaint:

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

When the button is clicked, call JPanel.repaint(). For example,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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