Codename One - Modify a font size in a theme like in an hashtable


In the previous question <a href="https://stackoverflow.com/questions/48797731/codename-one-method-to-enlarge-or-reduce-all-the-fonts-in-all-the-styles" rel="nofollow">Codename One - Method to enlarge or reduce all the fonts in all the styles</a> I replied with a method that iterates all the values of a theme and, if a given value is an istance of Font, it changes its font size of a given percentage.

The problem is that it doesn't work as expected, because some fonts are changed and others are not. For example, if I have the following font size of a Label (3.1mm) in my theme.xml, that Label font size it's not changed:

<font key="Label.font" type="ttf" face="0" style="0" size="0" name="native:MainThin" family="native:MainThin" sizeSettings="3" actualSize="3.1" />

What's wrong in the following code?

/** * Increases or reduces of a given percentage all the font sizes of a given * theme, overlaying a new theme containing only the new font sizes. The * font sizes will be increased when the percentage is positive, they will * be reduced when the percentage is negative. Legal percentage values are * from -90 to 300. * * Example of usage: changeFontSizesOfTheme(theme, "Theme", 50); * * @param theme the given resource file * @param themeName the name of given theme * @param percentage the given percentage to increase or reduce the font * sizes */ public static void changeFontSizesOfTheme(Resources theme, String themeName, int percentage) { if (theme.isTheme(themeName) && percentage != 0 && percentage >= -90 && percentage <= 300) { Hashtable hashtable = theme.getTheme("Theme"); Hashtable overlay = new Hashtable(); Set<String> keys = hashtable.keySet(); Iterator<String> itr = keys.iterator(); String key; Object value; int count = 0; while (itr.hasNext()) { key = itr.next(); value = hashtable.get(key); if (value instanceof Font) { Font originalFont = (Font) value; float originalFontSize = originalFont.getPixelSize(); float newFontSize = originalFontSize * (100 + percentage) / 100; overlay.put(key, originalFont.derive(newFontSize, originalFont.getStyle())); count++; } } UIManager.getInstance().addThemeProps(overlay); Log.p(count + " font sizes of the theme \"" + themeName + "\" were overlayed"); } }


The error was the line:

Hashtable hashtable = theme.getTheme("Theme");

The correct code is without the double quotes:

Hashtable hashtable = theme.getTheme(Theme);

That's all :)


  • How can I merge multiple OSGi bundles with BND / Maven-BND-plugin?
  • Example from three.js but how to implement using SceneKit?
  • How do I stop Yahoo displaying serif fonts in HTML emails when I've specified sans-serif?
  • How to embed a custom bitmap font into website using CSS
  • Printing out text of all GUI elements in Red language
  • Why are XML namespaces HTTP addresses?
  • flip box height of back side, also doesnot work on IE [duplicate]
  • Dynamic Programming - top-down vs bottom-up
  • What's the quickest and easiest way of getting libpng available for development in VisualStudio
  • Android HTTP Authentication
  • Error while trying to upload file using kairos
  • Render face of cube map to a quad
  • Webdriver Xpath Performance
  • printout webpage with @font-face
  • Extract text from “” HTML tag
  • Docker container for google cloudML on compute engine - authenticating for mounting bucket
  • Matplotlib rotate image file by X degrees
  • How to use arithmetic operators with SAS macro variables [duplicate]
  • UML diagram generator in Visual Studio 2010
  • Netlink sockets and libnl - nl_recvmsgs_default returning -16 (EBUSY)
  • CKeditor stripping font tags instead of converting to span
  • Embedded Glassfish JPA Datasource connection fail
  • Custom Tabgroup Appcelerator
  • Play WS (2.2.1): post/put large request
  • How do I alternate colors in Flat List (React Native)
  • Listbox within Listbox and scrolling trouble in Windows Phone 7 Silverlight
  • why do I get the error when installing the gem 'pg'? [duplicate]
  • Why value captured by reference in lambda is broken? [duplicate]
  • Deserializing XML into class C#
  • jquery mobile loadPage not working
  • Unanticipated behavior
  • Is there a mandatory requirement to switch app.yaml?
  • Why joiner is not used after Sequence generator or Update statergy
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Recursive/Hierarchical Query Using Postgres
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal