0 Replies Latest reply: Oct 28, 2010 11:58 AM by 322169 RSS

    Synth LAF and JTextField's disabled text color.

    322169
      I'm trying to implement my own look and feel using synth. I want the LAF to have user-defined colors, including text color for disabled JTextFields through the properties file.

      Unfortunately when I read the properties file and set the corresponding UIDefaults property, it gets ignored by SynthTextFieldUI:
      Color dfg = comp.getDisabledTextColor(); 
          if (dfg == null || dfg instanceof UIResource) {
              comp.setDisabledTextColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
      }
      So, if a color is specified, it promptly get's ignored, and is read from the xml <style> attribute. Nothing wrong with this, since styles are how synth does it's work, but how do I set the thing programatically?


      The only solutions I can come up with are sadly just hacks.
      SynthLookAndFeel synth = new SynthLookAndFeel();
      synth.load(LAFTest.class.getResourceAsStream("test.xml"), LAFTest.class);
      I could intercept loading of test.xml file and insert appropriate <style> tag contents on the fly. Or just generate the file dynamically.

      Or do this (ugly, ugly hack):
      public class TextFieldPainter extends SynthPainter {
      
          @Override
          public void paintTextFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) {
              ((JTextField)context.getComponent()).setDisabledTextColor(getColorFromPropertyFile());
              // carry on with painting...
          }