I have a simple Java program that allows a user to draw rectangles on a JPanel and then move them around, resize them and delete them.
The drawing panel implements MouseListener and MouseMotionListener. When an event is fired, it checks which menu option is selected (new rectangle, move, resize or delete) and reacts accordingly.
When the "resize" option is selected, the listener methods do the following:
MouseMoved calls boolean detectBoundary (). When this returns true, the rectangle to which the border belongs is set as the active rectangle.
MouseDragged calls a void moveBoundary, which moves the detected border in the direction of the drag gestures.
Now what I'm looking for is a way to make a border that will move, stand out. I can re-draw the entire rectangle in thicker lines or in a different color, which Iβm doing now when I set this rectangle to be active, but thatβs not what I want. I would like to repaint only one border.
The setBorder method, which can handle the BorderFactory createMatteBorder method, seems ideal for these purposes, but I could not find a way to do this work.
Does anyone have an idea how I could do this?
All suggestions will be greatly appreciated.
source share