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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:40:00+00:00 2026-05-18T04:40:00+00:00

I have an application where I need to change font sizes frequently. A question

  • 0

I have an application where I need to change font sizes frequently. A question posted a year ago on this forum (Change just the font size in SWT) gave me some of the information I needed, but I’ve still got some unknowns I haven’t figured out yet.

In particular, someone signing as hudsonb offered a helpful code fragment which I’d like to reproduce below:

FontData[] fontData = label.getFont().getFontData();
for(int i = 0; i < fontData.length; ++i)
    fontData[i].setHeight(14);

final Font newFont = new Font(display, fontData);
label.setFont(newFont);

// Since you created the font, you must dispose it
label.addDisposeListener(new DisposeListener() {
    public void widgetDisposed(DisposeEvent e) {
        newFont.dispose(image);
    }
});

Suppose I used code like this to change font sizes frequently. Aren’t I creating a whole sequence of DisposeListeners, and adding them to the label’s listener queue? Don’t I need to remove the previous listener each time before adding a new listener? Or is there some mechanism I don’t understand that makes this unnecessary?

  • 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-18T04:40:01+00:00Added an answer on May 18, 2026 at 4:40 am

    An alternative would be to add a DisposeListener that maintains a list of Fonts it needs to dispose of when finished with, e.g.

    class FontDisposer implements DisposeListener {
        private List<Font> toDispose;
    
        public FontDisposer() {
            toDispose = new ArrayList<Font>();
        }
    
        @Override
        public void widgetDisposed(DisposeEvent e) {
                // Dispose all fonts in toDispose
        }
    
        public void registerFont(Font f) {
            toDispose.add(f);
        }
    }
    
    class UIWotsit extends SomeUIClass {
        private FontDisposer disposer;
    
        public UIWotsit() {
            disposer = new FontDisposer();
            addDisposeListener(disposer);
        }
    
        public void changeFont(Font f) {
            disposer.registerFont(f);
            // Do all the font changing stuff
        }
    }
    

    This may not suit your particular application but having something that maintains a list of Fonts is probably a reasonable start. You could also use an anonymous DisposeListener that calls a method in whatever code manages the Font creation/changing/disposal:

    class OtherFontDisposer implements DisposeListener {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            myCleverFontManager.disposeOfAll();
        }
    }
    

    It all depends on whether you are creating new labels or not, and whether you want to dispose of Fonts immediately or only when the UI is disposed of.

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

Sidebar

Related Questions

I have this application that need to do some things in protected paths (like
I have a silverlight 4.0 application where I need to change the Window Title
I have an application developed on MVC2 but I need it to change from
I have two application that need to talk to each other. App1 needs to
I have an application I need to analyze. I have the source code here.
I have an application where I need to fire a notification on certain days
I have an application where I need to INSERT an auto_increment value from a
Hokay so I have an application where I need some IPC... I'm thinking named
i have an application that has a dependancy on gdiplus. i need the application
I have a phonegap application which will need to take a zip archive of

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.