LWUIT: Button Text Alignment CENTER jump to LEFT when selected
Hello All,
I am using LWUIT for the Series 40 below.
[url]http://projects.developer.nokia.com/LWUIT_for_Series_40[/url]
I am using the S40-no-themes.jar.
I have the sample code below. The problem, I'm having is when I select the "Hello" button, the text will jump to LEFT. Can anyone help me. Thanks in advance.
[CODE]
import javax.microedition.midlet.*;
import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
import com.sun.lwuit.layouts.BoxLayout;
public class HelloWorld extends MIDlet implements ActionListener {
public void startApp() {
Display.init(this);
Form f = new Form("Hello, LWUIT!");
f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Button hello = new Button("Hello");
hello.getStyle().setAlignment(Component.CENTER);
hello.getSelectedStyle().setAlignment(Component.CENTER);
f.addComponent(hello);
f.show();
Command exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.addCommandListener(this);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}
[/CODE]
Re: LWUIT: Button Text Alignment CENTER jump to LEFT when selected
I do not know LWUIT, but according to the docs there might be a getPressedStyle too.
Re: LWUIT: Button Text Alignment CENTER jump to LEFT when selected
[QUOTE=wizard_hu_;902048]I do not know LWUIT, but according to the docs there might be a getPressedStyle too.[/QUOTE]
Thanks, I used "getPressedStyle" and it works now.
I am wondering what does getSelectedStyle() mean then.
Re: LWUIT: Button Text Alignment CENTER jump to LEFT when selected
Well, I really do not know LWUIT. Just checked the docs, exactly because getSelectedStyle looked suspicious. I think it may have something to do with focusing. For example if the device has no touchscreen so the user navigates between the controls with a joypad. I can imagine that this SelectedStyle is applied to show the current control. But still, this is just a guess, I have not used LWUIT.
Re: LWUIT: Button Text Alignment CENTER jump to LEFT when selected
Thanks. This makes sense.
Re: LWUIT: Button Text Alignment CENTER jump to LEFT when selected
getSelectedStyle() -- Returns the Component Style when it owns focus
getPressedStyle()---Returns the Component Style when it is pressed
You can’t see getSelectedStyle() in full touch devices(full touch devices don’t have focus), but it can easily visible in non-touch or Touch & Type devices.
I tested following code in S40 SDK 1.1
[QUOTE]Button hello = new Button("Hello");
hello.getStyle().setAlignment(Component.CENTER);
hello.getSelectedStyle().setAlignment(Component.RIGHT);
hello.getPressedStyle().setAlignment(Component.LEFT);[/QUOTE]
getSelectedStyle() returns when touched the button
getPressedStyle() returns when button is pressed and hold.