Skip to main content

Aplying a gradient background to title and softbutton

4 replies [Last post]
cachapa
Offline
Joined: 2008-10-14

Hi,

I'm trying to apply a gradient background to the title and softbutton styles, but I'm not having much success.
If I try setting the style directly to a specific form instance, it works:

mainForm.getTitleStyle().setBgPainter(new LinearGradientPainter(0, 0xffffff, false));<br />
mainForm.getSoftButtonStyle().setBgPainter(new LinearGradientPainter(0, 0xffffff, false));

But when I try to set the style to the UIManager, so that it affects all the elements in the application, it fails:

Style s = ui.getComponentStyle("Title");<br />
s.setBgPainter(new LinearGradientPainter(0, 0xffffff, false));<br />
ui.setComponentStyle("Title", s);

I know that that code is at least half correct because I can call s.setFgColor(0x00ff0000); and it changes the color for all the titles in my application.

Here is the full code:

import com.sun.lwuit.Command;<br />
import com.sun.lwuit.Display;<br />
import com.sun.lwuit.Form;<br />
import com.sun.lwuit.events.ActionEvent;<br />
import com.sun.lwuit.events.ActionListener;<br />
import com.sun.lwuit.plaf.Style;<br />
import com.sun.lwuit.plaf.UIManager;<br />
import javax.microedition.midlet.MIDlet;</p>
<p>public class Test extends MIDlet implements ActionListener {</p>
<p>	public void startApp() {<br />
		Display.init(this);<br />
		UIManager ui = UIManager.getInstance();</p>
<p>		Style s = ui.getComponentStyle("Title");<br />
		s.setBgPainter(new LinearGradientPainter(0, 0xffffff, false));<br />
		s.setFgColor(0x00ff0000);<br />
		ui.setComponentStyle("Title", s);</p>
<p>		s = ui.getComponentStyle("SoftButton");<br />
		s.setBgPainter(new LinearGradientPainter(0, 0xffffff, false));<br />
		s.setFgColor(0x00ff0000);<br />
		ui.setComponentStyle("SoftButton", s);</p>
<p>		Form f = new Form("Hello, LWUIT!");<br />
		f.show();</p>
<p>		f.addCommand(new Command("Item 1"));<br />
		f.addCommand(new Command("Item 2"));<br />
		f.addCommand(new Command("Item 3"));<br />
		f.setCommandListener(this);<br />
	}</p>
<p>	public void pauseApp() {<br />
	}</p>
<p>	public void destroyApp(boolean unconditional) {<br />
	}</p>
<p>	public void actionPerformed(ActionEvent ae) {<br />
		notifyDestroyed();<br />
	}<br />
}

The LinearGradientPainter class is taken verbatim from here: http://lwuit.blogspot.com/2008/07/pimp-my-lwuit-part-1-gradient-galore.html

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Shai Almog

Hi,
I'm afraid we made some changes to the softbutton style preventing
this from working. We use merge within refresh theme rather than
replacing the style, since the style is rather elaborate and applied
to several components.

> Hi,
>
> I'm trying to apply a gradient background to the title and
> softbutton styles, but I'm not having much success.
> If I try setting the style directly to a specific form instance, it
> works:
> [code]mainForm.getTitleStyle().setBgPainter(new
> LinearGradientPainter(0, 0xffffff, false));
> mainForm.getSoftButtonStyle().setBgPainter(new LinearGradientPainter
> (0, 0xffffff, false));[/code]
>
> But when I try to set the style to the UIManager, so that it
> affects all the elements in the application, it fails:
> [code]Style s = ui.getComponentStyle("Title");
> s.setBgPainter(new LinearGradientPainter(0, 0xffffff, false));
> ui.setComponentStyle("Title", s);[/code]
>
> I know that that code is at least half correct because I can call
> s.setFgColor(0x00ff0000); and it changes the color for all the
> titles in my application.
>
> Here is the full code:
> [code]import com.sun.lwuit.Command;
> import com.sun.lwuit.Display;
> import com.sun.lwuit.Form;
> import com.sun.lwuit.events.ActionEvent;
> import com.sun.lwuit.events.ActionListener;
> import com.sun.lwuit.plaf.Style;
> import com.sun.lwuit.plaf.UIManager;
> import javax.microedition.midlet.MIDlet;
>
> public class Test extends MIDlet implements ActionListener {
>
> public void startApp() {
> Display.init(this);
> UIManager ui = UIManager.getInstance();
>
> Style s = ui.getComponentStyle("Title");
> s.setBgPainter(new LinearGradientPainter(0, 0xffffff, false));
> s.setFgColor(0x00ff0000);
> ui.setComponentStyle("Title", s);
>
> s = ui.getComponentStyle("SoftButton");
> s.setBgPainter(new LinearGradientPainter(0, 0xffffff, false));
> s.setFgColor(0x00ff0000);
> ui.setComponentStyle("SoftButton", s);
>
> Form f = new Form("Hello, LWUIT!");
> f.show();
>
> f.addCommand(new Command("Item 1"));
> f.addCommand(new Command("Item 2"));
> f.addCommand(new Command("Item 3"));
> f.setCommandListener(this);
> }
>
> public void pauseApp() {
> }
>
> public void destroyApp(boolean unconditional) {
> }
>
> public void actionPerformed(ActionEvent ae) {
> notifyDestroyed();
> }
> }[/code]
>
> The LinearGradientPainter class is taken verbatim from here: http://
> lwuit.blogspot.com/2008/07/pimp-my-lwuit-part-1-gradient-galore.html
> [Message sent by forum member 'cachapa' (cachapa)]
>
> http://forums.java.net/jive/thread.jspa?messageID=313835
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

cachapa
Offline
Joined: 2008-10-14

Hi Shai,

you left me scratching my head with your answer :-) I guess I'm not sufficiently familiar with the LWUIT architecture to understand what you said.

So you mean that there's currently no solution to this problem? I wouldn't mind setting the gradient individually to each form in my application (there aren't that many), but when I open a menu, it comes with the default soft button style, and it makes the app UI look inconsistent.

If that's the case, do you expect that this functionality will be reapplied in the near future?

Shai Almog

Hi,
we can take a look at that.
There are some technical difficulties with more common use cases, you
can open an issue in the issue tracker if you want to keep track of
this.

> Hi Shai,
>
> you left me scratching my head with your answer :-) I guess I'm not
> sufficiently familiar with the LWUIT architecture to understand
> what you said.
>
> So you mean that there's currently no solution to this problem? I
> wouldn't mind setting the gradient individually to each form in my
> application (there aren't that many), but when I open a menu, it
> comes with the default soft button style, and it makes the app UI
> look inconsistent.
>
> If that's the case, do you expect that this functionality will be
> reapplied in the near future?
> [Message sent by forum member 'cachapa' (cachapa)]
>
> http://forums.java.net/jive/thread.jspa?messageID=313860
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

cachapa
Offline
Joined: 2008-10-14

Hi,

thanks for the reply. I opened an issue in the issue tracker.