i want to assign a label to the TextField. I am using the following code
TextField textField = new TextField();
Label label = new Label("Pick a unique username");
textField.setLabelForComponent(label);
textField.setConstraint(TextField.ANY);
form.addComponent(textField);
form.show();
the above code is not showing the associated label for the TextField. How can it be done ?
An excerpt of the Component from the LWUIT javadoc # link
public void setLabelForComponent(Label componentLabel)
Allows us to indicate the label associated with this component thus providing
visual feedback related for this component e.g. starting the ticker when the
component receives focus.
Parameters:
componentLabel - a label associated with this component
Hence your are just associating a Label with this Component and now actual binding them together as perceived / visually single group.
.
I would recommend you use ComponentGroup with TextField and Label added to it, also you can style them as a group. Check this link for more information on ComponentGroup
PS: ComponentGroup is available from LWUIT 1.5.
Related
I have several escenarios where some mgwt widgets which do not extend TouchWidget need to be "touchable", for instance ScrollPanel or FlexPanel.
One scenario is a full screen widget wich reacts when user touches it and shows a popup.
Java do not let extending two classes, so I want to reuse code from both the widget and the TouchWidget (which has a final static TouchWidgetImpl in it)
Thanks
You don't need to make a FlexPanel into a TouchWidget. You can add a TouchWidget to a FlexPanel, and let it occupy the entire screen.
I want to have a menu for my program. And I like the standard Menu look and all, but I want to place a "logout-button" on the far right side of the menu-bar.. is it possible to place it there WITHOUT having to fill up the whole menu-bar with entries?
Sincerely
Yes you can. Use the HBox#setHgrow();. This javadoc page also has an example how to use it in "Optional Layout Constraints" section. Following is taken from javadoc.
For example, if an hbox needs the TextField to be allocated all extra space:
HBox hbox = new HBox();
TextField field = new TextField();
HBox.setHgrow(field, Priority.ALWAYS);
hbox.getChildren().addAll(new Label("Search:"), field, new Button("Go"));
Briefly speaking, set Priority.ALWAYS for the button (or any control) just before the "logout-button" in a HBox. More advanced example is here: Using Built-In Layout Panes : Example 1-4
I want to know how to create a label that contains two icons, one on each side and set it as the title bar for the form element (LWUIT widgets).
Form has a function to get a titleArea then you can put some components what you want.
Form f = new Form();
Container c = f.getTitleArea();
Label iconLabel1 = new Label("leftIcon");//using Image
Label iconLabel2 = new Label("rightIcon");//using Image
c.addComponent(BorderLayout.WEST, iconLabel1);
c.addComponent(BorderLayout.EAST, iconLabel2);
You can just add a component to the north portion of the screen which is the recommended way that will work properly and won't break for newer versions of LWUIT/Codename One.
When you don't set a title it will just work and you can give it the Title UIID. LWUIT 1.5 and newer have a TitleArea container but I suggest you stay away from it since CodenameOne customizes it quite allot for iOS/Android 4.x etc.
Use the setTitleComponent(Label title) method.
EDIT :
Derive the Label class and implement the paint method where you can use the Graphics method to draw Images and texts. Also set the label's text position to Label.CENTER .
I have made a Container compound by a TextArea and a CheckBox. In my app, I create so many of this "Containers" and add to each TextArea inside of them an ActionListener (implemented by the class). Something like this:
for(int i = 0 ; i<20;i++){
MyContainer c = new MyContainer();
TextArea t = c.getTextArea();
t.addActionListener(this);
}
I want the TextArea to catch the event and if it is pressed put the CheckBox checked or unchecked. It works fine in non-touch devices and simulators but in the touch devices or emulators, the TextArea doesn't catch the event. I tried to put the TextAreaas the lead component of the Container but it doesn't works because Container doesn't have an addActionListener method.
If I understand the question correctly you are trying to create a compound component assembled from multiple different components to act like a single component. In LWUIT/Codename One this is called a Lead Component, the attached post is mostly about the resource editor but the concepts apply to manual coding as well.
Just set the "checkbox" as your lead and everything should work.
You can code this manually by deriving and overriding but you will there are small edge cases like the change of style states (focused/pressed state etc.)
It is better that you derive the TextArea class for the getTextArea() method. Then in this class implement the pointerReleased method : code the action performed in the normal way in it.
I have a simple maps app with multiple pins on a map view. My intention is to tap a pin, show a callout with an accessory view, push to a Detail View Controller where you can edit that pin/locations details. This all works fine, but once i pop the Detail View Controller the callout on the map view is still there, which i want, but it still has the old uneditied values. How can i refresh/update the callout view once the Detail View Controller is popped?
I am using Core Data with a simple database. I have tried using controllerdidchangecontent, Map View Controller Will Display methods etc but my main problem is identifying which object has been added/updated/deleted and which is the corresponding callout/selected pin.
Any help appreciated...
Not sure if you had find your answer but the way to do it is to extend MKAnnotation class and creating custom annotation and passing them while creating placemarks. Later you can get them from MKAnnotationView's annotation property.
See a good implementation here
http://www.slideshare.net/360conferences/getting-oriented-with-mapkit-everything-you-need-to-get-started-with-the-new-mapping-framework
The only way I could find to update the callout info was to mess directly with the subviews of the callout.
The callout view is the first subview of the annotation view.
In the following example, I update the subtitle.The title label is the 6th and the subtitle is the 7th subview of the callout:
if (myAnnotationView.subviews.count > 0)
((UILabel*)[((UIView*)[myAnnotationView.subviews objectAtIndex:0]).subviews objectAtIndex:7]).text = #"Some example";