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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:21:13+00:00 2026-05-16T16:21:13+00:00

I have a field which extends BitmapField (called AnimatedGIFField) and an AnimatorThread (extending Thread)

  • 0

I have a field which extends BitmapField (called AnimatedGIFField) and an AnimatorThread (extending Thread) which does the work of looping through the GIF frames, incrementing the current frame and invalidating the field, which calls the paint() method to draw the next frame (resulting in animation). The animation code works fine, but my issue is in the paint() method of the AnimatedGIFField class. I’m calling ‘graphics.drawImage()‘ and I’m having trouble getting proper positions for x and y (the first two args to drawImage()). Positioning the AnimatedGIFField is working and is accomplished by overriding ‘getPreferredWidth()’ and ‘getPreferredHeight()’. The relevant code is here:

public class AnimatedGIFField extends BitmapField {

    /**
      The current frame in the animation sequence; the AnimatorThread
      increments this so paint() knows which frame to draw.
    */
    private int currentFrame;

    public AnimatedGIFField(GIFEncodedImage image, long style) {
        super(image.getBitmap(), style);
        this.image = image;
        this.preferredWidth  = this.image.getWidth();
        this.preferredHeight = -(this.image.getHeight() * 4);
    }

    protected void paint(Graphics graphics) {
        // Calling super draws the first background frame.
        super.paint(graphics);

        // Don't redraw if this is the first frame.
        if (this.currentFrame != 0) {
            // Draw the animation frame.

            /* getFrameLeft() and getFrameTop() both return the top left-most position (0, 0). */
            /* graphics.drawImage(this.image.getFrameLeft(this.currentFrame), */
            /*                    this.image.getFrameTop(this.currentFrame), */
            /*                    this.image.getFrameWidth(this.currentFrame), */
            /*                    this.image.getFrameHeight(this.currentFrame), */
            /*                    this.image, this.currentFrame, 0, 0); */

            /*
              Currently trying some hackish nonsense like this to position the frame, although
              it probably won't scale properly across different devices/screen sizes.
            */
            int x = (this.getManager().getWidth() / 2) - 45;
            int y = (this.getManager().getHeight() / 2) + 83;

            graphics.drawImage(x, y,
                               this.image.getFrameWidth(this.currentFrame),
                               this.image.getFrameHeight(this.currentFrame),
                               this.image, this.currentFrame, 0, 0);
        }
    }
}
  • 1 1 Answer
  • 2 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-16T16:21:13+00:00Added an answer on May 16, 2026 at 4:21 pm

    Fixed the problem by stripping out all getPreferredWidth/Height stuff, removed the sublayout() method on my custom field and just overwrote layout() inside of my custom manager to position all fields (just the one) properly. That caused image.getFrameLeft() and image.getFrameTop() return proper values, which is where I had my positioning hacks before.

    Thanks for the responses. I was making it way more complicated than it needed to be.

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

Sidebar

Related Questions

I've a text field which extends javax.swing.JTextField and also have document listener like this
I have form called LoginForm, which extends the RecipeForm which in turn extends Zend_Form.
I have a class called 'Items' to which 'Equips' extends from and 'Helmet' then
I have a class which is extending Application public class MyContext extends Application {
I would like to have a field which is updated on every change(insertion, modification),
in my database we have a field which is going beyond int max value,
I use yui datatable and i have a field which is resumePath which is
I have an input field which has a placeholder text. I want one word
I have a form field which requires a json object as its value when
I have a field 'Description' which can have product descriptions with any unicode characters.

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.