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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:17:41+00:00 2026-05-30T17:17:41+00:00

I have several GUI forms in my java application. All of forms have texts.

  • 0

I have several GUI forms in my java application. All of forms have texts. I had set texts to my components from a shared object called dictionary. I need a feature in my program; to switch language as user wants; such that all texts in all forms be replaced with another language. I have all texts in a shared Dictionary object. is there any clean way to change language in a clean way?
I know about netbeans Internationalization tool but I want to use another method.

Edit: for example:

label1.setText(Dictionary.Hello);

and Dictionary class is defined as:

 public class Dictionary {
     public static String Hello = "hello"; 
}

and for another language:

  public class DictionaryPersian extends Dictionary {
      public DictionaryPersian(){
          Hello = "درود"; 
       }
  }

I want to find a way way to bind the field Dictionary.hello to jlabel1 such that as this variable value changed it be reflected on jlabel1 text.

  • 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-30T17:17:42+00:00Added an answer on May 30, 2026 at 5:17 pm

    You could subclass JLabel for instance, setting text directly from the dictionary using some id. It can also act as listener to text or language changes to automatically change displayed text accordingly.

    For explanation sake some code snipped (not tested, nor complete, the dictionary label can be implemented differently if you like, also your dictionaries should implement IDictionary)

    public interface IDictionaryListener {
      void dictionaryChanged(IDictionary from, IDictionary to);
    }
    
    public interface IDictionary {
      String getString(String forKey);
    }
    
    public final class DictionaryManager {
      private static final DictionaryManager INSTANCE=new DictionaryManager();
      private final List<IDictionaryListener> listeners=new ArrayList<>();
      private IDictionary dictionary;
    
      private DictionaryManager() {};
    
      public static synchronized void setDictionary(IDictionary dict) {
        IDictionary old = INSTANCE.dictionary;
        INSTANCE.dictionary=dict;
        fireDictionaryChanged(old, dict);
      }
    
      public static synchronized IDictionary getDictionary() {
        return INSTANCE.dictionary;
      }
    
      public static synchronized void addDictionaryListener(IDictionaryListener l) {
        INSTANCE.listeners.add(l);
      }
    
      public static synchronized void removeDictionaryListener(IDictionaryListener l) {
        INSTANCE.listeners.remove(l);
      }
    
      private static void fireDictionaryChanged(IDictionary from, IDictionary to) {
        for (IDictionaryListener l:INSTANCE.listeners) {
          l.dictionaryChanged(from, to);
        }
      }
    
    }
    
    public class DictionaryLabel extends JLabel implements IDictionaryListener {
      private String key;
    
      public DictionaryLabel(String dictKey) {
        super();
        key = dictKey;
        DictionaryManager.addDictionaryListener(this);
        super.setText(DictionaryManager.getDictionary().getString(key));
      }
    
      @Override
      public final void setText(String text) {
        throw new RuntimeException("Not supported! Dictionary is used for this!");
      }
    
      @Override
      public void dictionaryChanged(final IDictionary from, final IDictionary to) {
        SwingUtilities.invokeLater(new Runnable() {
    
          @Override
          public void run() {
            DictionaryLabel.super.setText(to.getString(key));
          }
    
        });
      }
    }
    

    As I said, just some example snipped I hope you get the idea.

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

Sidebar

Related Questions

I have a function that is called by several GUI components, and always needs
I am developing an application in Java, in my GUI I have several JPanels
I have a question regarding SwingWorker and Java GUI's. I have several classes which
I have a swing gui with a tabbed pane in the north. Several key
I have several RequiredFieldValidators in an ASP.NET 1.1 web application that are firing on
I have a GUI written using netbeans with a few simple components in place.
I have a c# windows form application that has a similar GUI functionality as
I have a rather simple multi-threaded VCL gui application written with Delphi 2007. I
In our application we sometimes have to make minor GUI modifications for different customers:
I have set up a dialog with several tabs. One of these contains twenty

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.