Google Tag Manager

2011/02/03

Translucent JInternalFrame (Nimbus)

Code

class MySynthStyleFactory extends SynthStyleFactory {
  private SynthStyleFactory wrappedFactory;
  public MySynthStyleFactory(SynthStyleFactory factory) {
    this.wrappedFactory = factory;
  }
  public SynthStyle getStyle(JComponent c, Region id) {
    SynthStyle s = wrappedFactory.getStyle(c, id);
    //if(id==Region.INTERNAL_FRAME_TITLE_PANE||id==Region.INTERNAL_FRAME) {
    if(id==Region.INTERNAL_FRAME) {
      s = new TranslucentSynthSytle(s);
    }
    return s;
  }
}
class TranslucentSynthSytle extends SynthStyle {
  private final SynthStyle style;
  public TranslucentSynthSytle(SynthStyle s) {
    style = s;
  }
  public SynthPainter getPainter(final SynthContext context) {
    return new SynthPainter() {
      public void paintInternalFrameBackground(SynthContext context,
                           Graphics g, int x, int y, int w, int h) {
        g.setColor(new Color(100,200,100,100));
        g.fillRoundRect(x,y,w-1,h-1,15,15);
      }
    };
  }
  public boolean isOpaque(SynthContext context) {
    if(context.getRegion()==Region.INTERNAL_FRAME) {
      return false;
    }else{
      return style.isOpaque(context);
    }
  }
  public Color getColorForState(SynthContext context, ColorType type) {
    return null; //Color.RED;
  }
  public Font getFontForState(SynthContext context) {
    return null; //new Font("MONOSPACE", Font.ITALIC, 24);
  }
  //...

References

6 comments:

  1. is this brown square background the correct button background behaviour?

    https://picasaweb.google.com/lh/photo/jpjqW6OXUbZr-UNEWXoeNw?feat=directlink

    ReplyDelete
  2. Oops, bit ugly...
    I think this will need to call JPanel#setOpaque(false):
    JPanel p2 = new JPanel() {
    @Override public void paintComponent(Graphics g) {
    g.setColor(new Color(100,50,50,100));
    g.fillRect(0,0,getWidth(), getHeight());
    }
    };
    p2.setOpaque(false);

    ReplyDelete
  3. la Nippa,
    Example.jnlp, src.zip update. Thank you for point out.

    ReplyDelete