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

  • SEARCH
  • Home
  • 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 8330135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:01:34+00:00 2026-06-09T02:01:34+00:00

I am changing the bounds of a JPanel using a Timer to get a

  • 0

I am changing the bounds of a JPanel using a Timer to get a sliding effect when someone hovers over a particular rectangular area, this is working as expected. There are buttons in the JPanel and they have different MouseEvent behaviors. But SOMETIMES it starts lagging or slides very slowly. Please, can anyone suggest what can I do, to ensure it performs well every time?

EDITED:

The buttonsPanel have button in it. buttonsPanel is added to a JLayeredPane which have bounds as rect. When JLayeredPane or JButton button is hovered mouse events are triggered. Mouse events then triggers the timer to slide the buttonsPanel and bring to it view.

class MyActionListener implements ActionListener {

    private static final int frames = 50;
    int count = 0;
    private final Timer timer = new Timer(1, this);

    public void start() {
        timer.start();
    }

    @Override
    public void actionPerformed(ActionEvent ae) {
        if (count >= frames) {
            timer.stop();
        } else {
            count = count + 1;
            buttonsPanel.setBounds(hidden_width - hidden_width * count / frames, 0, hidden_width, frameHeight);
        }
    }
}

class MyMouseListener extends MouseAdapter {

    private MyActionListener timerListener;

    @Override
    public void mouseEntered(final MouseEvent event) {

        final Color color = new Color(50, 50, 50);
        if (event.getSource() instanceof JButton) {
            final JButton button = (JButton) event.getSource();
            button.setBackground(color);
            buttonsPanel.setVisible(true);
        } else if (!buttonsPanel.isVisible()) {
            buttonsPanel.setVisible(true);
            timerListener = new MyActionListener();
            timerListener.start();
        }
    }

    @Override
    public void mouseExited(final MouseEvent event) {
        Point point = new Point(0, 0);
        if (event.getSource() instanceof JButton) {
            final JButton button = (JButton) event.getSource();
            point = button.getLocation();
            button.setBackground(Windows8GUI.color);
        }
        Rectangle rect = new Rectangle(0, 0, hidden_width, frameHeight);
        if (!rect.contains(point.x + event.getX(), point.y + event.getY())) {
            buttonsPanel.setVisible(false);
            buttonsPanel.setBounds(0, 0, hidden_width, frameHeight);
        }
    }
}
  • 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-06-09T02:01:39+00:00Added an answer on June 9, 2026 at 2:01 am

    The primary issue is you are assuming that you have control over the paint engine. You don’t, in fact, the paint engine is at the mercy of the OS. This means that you can jump up and down all you like, but until the OS and Java’s paint engine are ready, nothing will happen.

    In fact, if you call repaint repeatedly in quick succession you can find yourself flooding the paint engine with requests, slowing it down even further.

    While not a solution to the whole problem, it will make your life vastly simpler take a look at the TimingFramework or Trident.

    They are “animation” frameworks designed to take out the guess work and make your life easier. I personal use TimingFramework for all my animation and it works well.

    The timing frameworks work on a % over time. That is, you give it a time for a cycle and the frameworks will return a % value based on how far through that cycle they are. You can apply interpolations, allowing you to effect how fast a portion of the animation will play.

    Trident has also been designed to provide the means to call other methods on your behalf, so it could set the bounds of the button pane for you, based on values you supply it.

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

Sidebar

Related Questions

Given a rectangular area, I want to render some text using a specific font
After changing the import as a from-import i'm running into this error: from datetime
I'm using this public void drawSky(Canvas canvas) { float lineY =(CamOverlayTest.camViewCenterY/2)+3*(Math.max(0,(-90 - CamOverlayTest.swRoll))); int[]
My question is very similar to this one Not drawing outside bounds when clipToBounds=NO
In the debugger it crashes and i get this error but the object at
I'm wondering why there're two types(bounds/frame) for describing a view. Since changing a view's
I keep gettting array index out of bounds? Iv'e tried with changing mymatches.Count to
I am using CABasicAnimation to change the bounds property and then using it to
How do I go about changing the tab bar color in this code? My
Changing the open_basedir directive to work with subdomains works absolutely fine on my server

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.