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 7161219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:31:48+00:00 2026-05-28T13:31:48+00:00

I have java swing chess application. Cursor has custom view – rectangle, sized to

  • 0

I have java swing chess application. Cursor has custom view – rectangle, sized to fit whole cell. And I need cursor moving only over whole cell. Not in the limits of one cell. Is there some typical solutions for this problem? Or maybe it is possible to set with standard java capabilities step-type cursor moving?

enter image description here

  • 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-28T13:31:49+00:00Added an answer on May 28, 2026 at 1:31 pm

    I wouldn’t implement some kind of “stepping” cursor. Instead I would hide the cursor completly and highlight the current cell programmatically.

    • Hiding the cursor check out this question and answer.
    • Use a MouseMotionListener to get the movements of the mouse (and highlight it in the paintComponent method of your custom component

    Full example below that “outputs” this screenshot:

    screenshot

    public class StepComponent extends JComponent implements MouseMotionListener {
        private Point point = new Point(0, 0);
    
        public StepComponent() {
            setCursor(Toolkit.getDefaultToolkit().createCustomCursor(
                    new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), 
                    new Point(0, 0), "blank cursor"));
            addMouseMotionListener(this);
        }
    
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
    
            int x = 0, y = 0;
            while (x < getWidth()) { g.drawLine(x, 0, x, getHeight()); x += 10; }
            while (y < getHeight()) { g.drawLine(0, y, getWidth(), y); y += 10; }
            if (point != null)
                g.fillRect(point.x, point.y, 10, 10);
        }
        @Override public void mouseDragged(MouseEvent e) { update(e.getPoint()); }
        @Override public void mouseMoved(MouseEvent e) { update(e.getPoint()); }
    
        private void update(Point p) {
            Point point = new Point(10 * (p.x / 10), 10 * (p.y / 10));
            if (!this.point.equals(point)) {
                Rectangle changed = new Rectangle(this.point,new Dimension(10,10));
                this.point = point;
                changed.add(new Rectangle(this.point, new Dimension(10, 10)));
                repaint(changed);
            }
        }
    }
    

    And some test code:

    public static void main(String[] args) {
    
        JFrame frame = new JFrame("Test");
    
        frame.add(new StepComponent());
    
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 300);
        frame.setVisible(true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java Swing application, that has many JTextFields and a datamodel. When
I have a Java web application that has a 'disconnected' Java Swing desktop app.
I have a Java swing application with a panel that contains three JComboBoxe s
I have a Java Swing application, developed on Mac OS X 10.5 using Java
I have a Java Swing application that is being used as a cluster application.
We have a client side application (Java/Swing) that we need an HTML rendering control
I've creating a Java Swing application and I realized that I have many many
I am making an application with Java Swing and i have a problem. I
So I have this nice spiffy MVC-architected application in Java Swing, and now I
I would like to create extend a Java Swing application to have a look

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.