Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Synth: tileable backgrounds

843806Dec 8 2007
Hello world. As far as I've seen, there's no easy way to make tileable background for a synth component using synth's xml configuration file. Hopefully, they'll support that feature in the future releases.

Till then, here's a workaround, using custom SynthPainter to make jPanel's background tileable:
...
    <style id="panelStyle">
        <object id="background" class="TilePainter"/>
        <imageIcon id="icon" path="tile.png"/>
        <property key="recoder" value="icon"/>
        <painter method="panelBackground" idref="background"/>
    </style>
    <bind style="panelStyle" type="Region" key="Panel"/>
...
public class TilePainter extends SynthPainter {
    public void paintPanelBackground(SynthContext context,
            Graphics g, int x, int y, int w, int h) {
        
        Graphics2D g2 = (Graphics2D)g;
        
        ImageIcon i=(ImageIcon)context.getStyle().getIcon(context,"recoder");
        Image im=i.getImage();
        BufferedImage bi=new BufferedImage(im.getWidth(null),im.getHeight(null),
                BufferedImage.TYPE_INT_RGB);
        bi.createGraphics().drawImage(im,0,0,null);
        
        TexturePaint tp=new TexturePaint(bi,new Rectangle(0,0,bi.getWidth(),bi.getHeight()));
        g2.setPaint(tp);
        g2.fill(g2.getClip());
    }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 5 2008
Added on Dec 8 2007
0 comments
83 views