0

I am trying to increase the size and fonts of all of the components in frames in my application. I found some code which does so for the fonts via the code below:

private static void setUIFont(javax.swing.plaf.FontUIResource f)
{
    Enumeration<Object> keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements())
    {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof javax.swing.plaf.FontUIResource)
        {

            UIManager.put(key, f);
        }
    }
}

and then calling it via :

setUIFont (new javax.swing.plaf.FontUIResource(new Font("Tahoma",Font.PLAIN, 14)));

Since it worked I thought I will just try and modify it to use DimensionUIResource like seen below:

private static void setUISize(javax.swing.plaf.DimensionUIResource f)
{
    Enumeration<Object> keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements())
    {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof javax.swing.plaf.DimensionUIResource)
        {

            UIManager.put(key, f);
        }
    }
}

and calling it via:

setUISize (new javax.swing.plaf.DimensionUIResource(200, 200));

Unfortunately it doesn't work. Any idea what I am doing wrong with this code? Is there some other way to do it ?

f78xd23
  • 117
  • 2
  • 15
  • 2
    If you change the Font, then the component will resize automatically. If it doesn't then invoke `revalidate()` and `repaint()` on the frame. – camickr May 08 '14 at 20:26

1 Answers1

2

Just print the key and value and look what is included in DimensionUIResource.

Only below components will re-size.

OptionPane.minimumSize       : javax.swing.plaf.DimensionUIResource[width=262,height=90]
ProgressBar.verticalSize     : javax.swing.plaf.DimensionUIResource[width=12,height=146]
ScrollBar.minimumThumbSize   : javax.swing.plaf.DimensionUIResource[width=8,height=8]
ScrollBar.maximumThumbSize   : javax.swing.plaf.DimensionUIResource[width=4096,height=4096]
ToolBar.separatorSize        : javax.swing.plaf.DimensionUIResource[width=10,height=10]
ProgressBar.horizontalSize   : javax.swing.plaf.DimensionUIResource[width=146,height=12]th=146,height=12]
Braj
  • 46,415
  • 5
  • 60
  • 76
  • I see, is there any way to resize width and height of buttons, textfields and labels so that they can contain the increased font sizes? – f78xd23 May 08 '14 at 20:30
  • Let me try if there is any way to set the width and height of all the components globally. – Braj May 08 '14 at 20:32
  • @honest_questions, `is there any way to resize width and height of buttons, textfields and labels so that they can contain the increased font sizes?` - did you read my comment? This should work unless of course you are using a null layout, in which case you are on your own because you should NOT be using a null layout for this exact reason. Post your [SSCCE](http://www.sscce.org/) that demonstrates the problem if you need more help. – camickr May 08 '14 at 20:40
  • Oh man, sorry didn't see it and ....yes it actually does increase the button size. Apologies. – f78xd23 May 08 '14 at 20:48