Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 611191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:45:24+00:00 2026-05-13T17:45:24+00:00

I have a simple Java program that allows a user to draw rectangles on

  • 0

I have a simple Java program that allows a user to draw rectangles on a JPanel, then move them around, resize them, and delete them.

The drawing panel implements MouseListener and MouseMotionListener. When an event is triggered, it checks which menu option is selected (new rectangle, move, resize, or delete), and reacts accordingly.

When the ‘resize’ option is selected, the listener’s methods do the following:

  • MouseMoved calls boolean detectBoundary(). When that returns true, the rectangle to which the boundary belongs is set as the active rectangle.

  • MouseDragged calls void moveBoundary, which moves the detected boundary in the direction of the dragging gesture.

Now what I am looking for is a way to make the boundary that is going to be moved stand out. I can re-paint the whole rectangle in thicker lines or a different color, which is what I do now when I set a given rectangle as the active one, but that’s not what I want. I’d like to re-color just the one boundary.

A setBorder method that can handle BorderFactory’s createMatteBorder method would seem to be ideal for these purposes, but I haven’t been able to find a way to make that work.

Does anyone here have an idea how I could accomplish this?

All suggestions will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:45:24+00:00Added an answer on May 13, 2026 at 5:45 pm

    Could you call the setColor(Color color) method on java.awt.Graphics?

    It sounds like you might be asking for something more complicated, but I’m not sure exactly what.
    If you want two different boundary colors on the same rectangle, I think you would have to use two rectangle objects to do this. The top rectangle would have a transparent fill. The two rectangles would need to move together, and the second rectangle would need to be removed from the view when the move is complete.

    I’m not sure if it is possible to change the color of just one edge of a simple rectangle, but you could build a more complex shape out of multiple shapes, or alternatively you could draw your rectangle into a BufferedImage and draw a line over the top in a different color.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The Entity Framework designer is terrible - I've had the… May 14, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer If by "hijack" you meant sniff the packets then what… May 14, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer If you want two actions to be atomic, embed them… May 14, 2026 at 5:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.