0

I have a J2ME LWUIT app and I'm trying to change the width and background color of a button. The button is in a BoxLayout. I'm using code like this:

    btnLogout.setPreferredW(210);
    btnLogout.getStyle().setFgColor(0x00dcc5);
    btnLogout.getStyle().setBgColor(0x302d36);

Only the setFgColor line seems to work. The width remains unchanged and the background remains white. How can I change the style of the button? I haven't had this problem with other components (labels, text fields, etc...)

James Harpe
  • 4,315
  • 8
  • 47
  • 74

1 Answers1

2

If you are using the nokia sdk 2.0 to build your app, you should know that the Button's and native elements (Checkbox, ComboBox, etc)style is predefined by the system, so you can't change the native background using this methods.

I don't recommend you to change this values. If you want to build an app following the Nokia S40 guidelines, you must keep the native elements as they are.

If you still want to change this background.

You must open the .res file attached to your project (if you have made a custom .res...if you are using the .res from the Nokia sdk...you must find the source code for the library (is nokia page) and there you can find the .res). In the .res file you can create a new style for your custom Button, and later in the code you must set it to your Button, using the setUIID method in your component....with the name that you have set in the .res file.

Mun0n
  • 4,438
  • 4
  • 28
  • 46
  • But setPreferredW isn't part of style. Why can't I change that? – James Harpe Sep 20 '13 at 12:49
  • Ok, did you try with setWidth? – Mun0n Sep 20 '13 at 13:23
  • If this doesn't work...try another layout, to make the Button resizable with the orientation screen changes – Mun0n Sep 20 '13 at 13:25
  • setWidth does not work...I'm not sure I understand the rest of your comment. The component is currently in a BoxLayout. – James Harpe Sep 20 '13 at 20:07
  • What I want to say is that using a single value to set the button width is not a good practice in order to resize the component when the orientation of the screen changes. I don't know why, but setPrefferedW, must work. Try different values. – Mun0n Sep 22 '13 at 20:43