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?
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();
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
精彩评论