1

How can I make an image button with transparent background?

The default background is grey color, I created the button with empty text and setIcon, something like this:

    backButton = new Button(); //"Back");
    backButton.setIcon(backIcon);

    iface.createRoot(AxisLayout.vertical(), ROOT, modeLayer).
            setStyles(make(VALIGN.top, HALIGN.right)).
            setBounds(0, 0, width, height).
            add(backButton);

But could not figure out how to make the button to be transparent from the API / source code.

Any help / hint greatly appreciated.

Chii
  • 14,540
  • 3
  • 37
  • 44
mamamia
  • 179
  • 1
  • 7
  • great answer from Michael : https://groups.google.com/forum/?fromgroups#!topic/ooo-libs/FaaANe7LgC4 – mamamia Feb 11 '12 at 17:46

1 Answers1

2

You want to use Style.BACKGROUND.

If you want all buttons in your entire UI to have a blank background, then configure your root stylesheet like so:

Stylesheet ROOT = SimpleStyles.newSheetBuilder().
 add(Button.class, Styles.none().
   add(Style.BACKGROUND.is(new NullBackground())).
   addSelected(Style.BACKGROUND.is(new NullBackground()))).
 create();

Root root = iface.createRoot(AxisLayout.vertical(), ROOT, modeLayer).etc().

If you just want a particular button to have a blank background, configure it on the button:

Styles blankBg = Styles.none().
   add(Style.BACKGROUND.is(new NullBackground()))
   addSelected(Style.BACKGROUND.is(new NullBackground());

Button backButton = new Button().addStyles(blankBg).setIcon(backIcon);

Note also that SimpleStyles defines the backgrounds for buttons. If you start with a completely blank stylesheet, you can omit background definitions for your buttons and they will be blank.

samskivert
  • 3,694
  • 20
  • 22