简体   繁体   中英

How to remove a line drawn between two labels

I want to remove a line connecting two labels. Actually, I want to remove a label after which the line connecting the label is also removed. How can I do it?

You can't "remove lines" in swing. You can only add stuff onto a component when drawing. Just don't draw the line.

Show us some code

Do the opposite to what you do when you add the line to the panel. Presumably you have an ArrayList containing "lines to be drawn". So, whenever you link two labels you add a line to the ArrayList. So now you would just remove the line from the ArrayList and repaint the panel.

To remove the component you just do:

panel.remove(...);
panel.revalidate();
panel.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