Results 1 to 4 of 4

Thread: Changing font sizes and TitledApplicationDialog

  1. #1
    Join Date
    Aug 2004
    Posts
    229

    Default Changing font sizes and TitledApplicationDialog

    I've noticed that the (really cool, btw) title and validation area of the TitledApplicationDialog seems to be pretty fixed in size. I'm using the JGoodies L&F and provide an option for the user to change their font size. Behind the scenes I call into UIManager.put(...) and then SwingUtilities.updateComponentTreeUI(...) in order to change font sizes. Most components and controls respond appropriately to this font size change, except TitledApplicationDialog, which always seems to maintain the same size for its title area, thus quickly becoming too small if the user increases their font. The text displayed in the title area has the new font size, its just that the title area itself never changes in size. Any ideas on how I can get the title area to track the font size change?

    - Andy

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    335

    Default

    Andy that's my fault. I made some changes to DefaultMessageAreaPane so that it's height is locked in to a specific number of lines but hard coded the font size... Previously it's height used to jump around as the message changed which was really annoying.

    I'm quite busy at the moment so I don't know when I'll be able to look at it, but feel free to send in a patch if you feel like fixing it yourself.

    Ollie

  3. #3
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    335

    Default

    Andy,

    Can you please post the code you use to change the font size.

    Thanks

    Ollie

  4. #4
    Join Date
    Aug 2004
    Posts
    229

    Default

    Sorry for the late reply - just got back from vacation. :-)
    Not the most elegant solution, but it seems to work for me:
    Code:
    import org.springframework.richclient.command.support.ApplicationWindowAwareCommand;
    
    import java.awt.Font;
    import javax.swing.UIManager;
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    import javax.swing.plaf.FontUIResource;
    
    public class FontAdjustActionCommand extends ApplicationWindowAwareCommand
    {
      private double fontAdjustment = +1.0d;
    
      public double getFontAdjustment()
      {
        return this.fontAdjustment;
      }
    
      public void setFontAdjustment(final double fontAdjustment)
      {
        this.fontAdjustment = fontAdjustment;
      }
    
      protected void adjustFont(final double adjustAmount)
      {
        final Object[] objs = UIManager.getLookAndFeel().getDefaults().keySet().toArray();
        for&#40;int i = 0;i < objs.length;i++&#41; &#123;
          if&#40;objs&#91;i&#93;.toString&#40;&#41;.toUpperCase&#40;&#41;.indexOf&#40;"FONT"&#41; != -1&#41; &#123;
            final Font font = UIManager.getFont&#40;objs&#91;i&#93;&#41;;
            UIManager.put&#40;objs&#91;i&#93;, new FontUIResource&#40;font.deriveFont&#40;&#40;float&#41;&#40;font.getSize&#40;&#41; + adjustAmount&#41;&#41;&#41;&#41;;
          &#125;
        &#125;
    
        final JFrame applicationWindow = getParentWindowControl&#40;&#41;;
        SwingUtilities.updateComponentTreeUI&#40;applicationWindow&#41;;
        applicationWindow.repaint&#40;&#41;;
      &#125;
    
      //
      // METHODS FROM CLASS ActionCommand
      //
    
      protected void doExecuteCommand&#40;&#41;
      &#123;
        final double fontAdjustment;
    
        final Object fontAdjustmentParam = getParameter&#40;"fontAdjustment"&#41;;
        if&#40;fontAdjustmentParam != null&#41; &#123;
          if&#40;fontAdjustmentParam instanceof Number&#41; &#123;
            fontAdjustment = &#40;&#40;Number&#41;fontAdjustmentParam&#41;.doubleValue&#40;&#41;;
          &#125; else &#123;
            fontAdjustment = Double.parseDouble&#40;fontAdjustmentParam.toString&#40;&#41;&#41;;
          &#125;
        &#125; else &#123;
          fontAdjustment = getFontAdjustment&#40;&#41;;
        &#125;
    
        adjustFont&#40;fontAdjustment&#41;;
      &#125;
    &#125;
    Setting the fontAdjustment property will allow you to create both "increase font" and "decrease font" command instances from this single class.
    I'm not sure off the top of my head how long ago I checked out spring-rich - so this code may need to be revised a little if things have changed. I should note that the font adjustment loop was borrowed from a forum discussion on java.sun.com - though I can no longer remember who was the original author. Though I have modified the loop a little, if I do come across the info on the original author I'll post it in this thread to give proper credit.

    - Andy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •