Skip to main content

bug in form focus order

1 reply [Last post]
Anonymous

Hi,

I'm not sure this issue was discussed before but in the below example
the component focus order is wrong. The focus skips the combobox and
jumps to it after the button. If you start moving down during the
frame transition this does not occur!

how to reproduce:
click form2
(wait until transition is done)
now traverse through the commands by pressing down, the combobox will
be skipped.

CODE:

import com.sun.lwuit.Button;
import com.sun.lwuit.ButtonGroup;
import com.sun.lwuit.ComboBox;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.RadioButton;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.animations.Transition;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import java.util.Calendar;

/**
*
* @author francisdb
*/
public class TestForm extends Form {

public TestForm() {
super("Form1");

Command form2Command = new Command("Form2") {

public void actionPerformed(ActionEvent arg0) {
new Form2(TestForm.this).show();
}
};

this.addCommand(form2Command);
this.addCommand(new Command("Exit"));

}

/**
* Helper method that allows us to create a pair of components
label and the given
* component in a horizontal layout with a minimum label width
* @param label
* @param c
* @param minWidth
* @return
*/
protected Container createPair(String label, Component c, int minWidth) {
Container pair = new Container(new BorderLayout());
Label l = new Label(label);
l.setPreferredW(Math.max(l.getPreferredW(), minWidth));
l.getStyle().setBgTransparency(100);
pair.addComponent(BorderLayout.WEST, l);
pair.addComponent(BorderLayout.CENTER, c);
return pair;
}

private class Form2 extends Form {

private RadioButton maleRadioButton;
private RadioButton femaleRadioButton;
private ComboBox yearComboBox;
private Label pathLabel;
private Button pathButton;
private final Form parent;

public Form2(final Form parent) {
super("Form2");
this.parent = parent;
setMenuTransitions(null, null);
Command backCommand = new Command("back") {

public void actionPerformed(ActionEvent event) {
parent.show();
}
};

this.addCommand(new Command("nothing"));
this.addCommand(new Command("nothing2"));
this.addCommand(backCommand);
this.addCommand(new Command("nothing3"));

Transition out =
CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL,
false, 300);
Transition in =
CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL,
true, 300);
setTransitionInAnimator(in);
setTransitionOutAnimator(out);

this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

maleRadioButton = new RadioButton("Male");
femaleRadioButton = new RadioButton("Female");

ButtonGroup sexGroup = new ButtonGroup();
sexGroup.add(maleRadioButton);
sexGroup.add(femaleRadioButton);

Container sexContainer = new Container(new BorderLayout());
sexContainer.addComponent(BorderLayout.NORTH, maleRadioButton);
sexContainer.addComponent(BorderLayout.SOUTH, femaleRadioButton);
this.addComponent(createPair("Sex", sexContainer, 80));

int year = Calendar.getInstance().get(Calendar.YEAR);
String[] choices = new String[100];
for (int i = 0; i < 100; i++) {
choices[i] = String.valueOf(year - i);
}
yearComboBox = new ComboBox(choices);
//yearComboBox.addActionListener(this);
this.addComponent(createPair("Birth year", yearComboBox, 80));

pathLabel = new Label();
pathLabel.setFocusable(false);
pathButton = new Button(backCommand);

this.addComponent(createPair("Save path", pathButton, 80));
this.addComponent(pathLabel);

// this seems to be causing the bug
yearComboBox.setSelectedIndex(5);

pathLabel.setText("Test");
}
}
}

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

Reply viewing options

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

Hi,
Thanks for this issue... The bug is related to a special case that
got a bit out of hand, to workaround it just add:
c.getStyle().setMargin(0, 0, 0, 0);
or any other set of numbers to the setPair method. The important
point here that elements be aligned correctly to avoid that special
case.

I will try to fix it for the next drop (without breaking all the
focus fixes that went in...).

Thanks,
Shai.

> Hi,
>
> I'm not sure this issue was discussed before but in the below example
> the component focus order is wrong. The focus skips the combobox and
> jumps to it after the button. If you start moving down during the
> frame transition this does not occur!
>
> how to reproduce:
> click form2
> (wait until transition is done)
> now traverse through the commands by pressing down, the combobox will
> be skipped.
>
> CODE:
>
> import com.sun.lwuit.Button;
> import com.sun.lwuit.ButtonGroup;
> import com.sun.lwuit.ComboBox;
> import com.sun.lwuit.Command;
> import com.sun.lwuit.Component;
> import com.sun.lwuit.Container;
> import com.sun.lwuit.Form;
> import com.sun.lwuit.Label;
> import com.sun.lwuit.RadioButton;
> import com.sun.lwuit.animations.CommonTransitions;
> import com.sun.lwuit.animations.Transition;
> import com.sun.lwuit.events.ActionEvent;
> import com.sun.lwuit.layouts.BorderLayout;
> import com.sun.lwuit.layouts.BoxLayout;
> import java.util.Calendar;
>
> /**
> *
> * @author francisdb
> */
> public class TestForm extends Form {
>
> public TestForm() {
> super("Form1");
>
>
> Command form2Command = new Command("Form2") {
>
> public void actionPerformed(ActionEvent arg0) {
> new Form2(TestForm.this).show();
> }
> };
>
> this.addCommand(form2Command);
> this.addCommand(new Command("Exit"));
>
>
> }
>
> /**
> * Helper method that allows us to create a pair of components
> label and the given
> * component in a horizontal layout with a minimum label width
> * @param label
> * @param c
> * @param minWidth
> * @return
> */
> protected Container createPair(String label, Component c, int
> minWidth) {
> Container pair = new Container(new BorderLayout());
> Label l = new Label(label);
> l.setPreferredW(Math.max(l.getPreferredW(), minWidth));
> l.getStyle().setBgTransparency(100);
> pair.addComponent(BorderLayout.WEST, l);
> pair.addComponent(BorderLayout.CENTER, c);
> return pair;
> }
>
> private class Form2 extends Form {
>
> private RadioButton maleRadioButton;
> private RadioButton femaleRadioButton;
> private ComboBox yearComboBox;
> private Label pathLabel;
> private Button pathButton;
> private final Form parent;
>
> public Form2(final Form parent) {
> super("Form2");
> this.parent = parent;
> setMenuTransitions(null, null);
> Command backCommand = new Command("back") {
>
> public void actionPerformed(ActionEvent event) {
> parent.show();
> }
> };
>
> this.addCommand(new Command("nothing"));
> this.addCommand(new Command("nothing2"));
> this.addCommand(backCommand);
> this.addCommand(new Command("nothing3"));
>
>
> Transition out =
> CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL,
> false, 300);
> Transition in =
> CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL,
> true, 300);
> setTransitionInAnimator(in);
> setTransitionOutAnimator(out);
>
> this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
>
> maleRadioButton = new RadioButton("Male");
> femaleRadioButton = new RadioButton("Female");
>
> ButtonGroup sexGroup = new ButtonGroup();
> sexGroup.add(maleRadioButton);
> sexGroup.add(femaleRadioButton);
>
> Container sexContainer = new Container(new BorderLayout
> ());
> sexContainer.addComponent(BorderLayout.NORTH,
> maleRadioButton);
> sexContainer.addComponent(BorderLayout.SOUTH,
> femaleRadioButton);
> this.addComponent(createPair("Sex", sexContainer, 80));
>
>
> int year = Calendar.getInstance().get(Calendar.YEAR);
> String[] choices = new String[100];
> for (int i = 0; i < 100; i++) {
> choices[i] = String.valueOf(year - i);
> }
> yearComboBox = new ComboBox(choices);
> //yearComboBox.addActionListener(this);
> this.addComponent(createPair("Birth year",
> yearComboBox, 80));
>
> pathLabel = new Label();
> pathLabel.setFocusable(false);
> pathButton = new Button(backCommand);
>
> this.addComponent(createPair("Save path", pathButton,
> 80));
> this.addComponent(pathLabel);
>
> // this seems to be causing the bug
> yearComboBox.setSelectedIndex(5);
>
> pathLabel.setText("Test");
> }
> }
> }
>
> --
> http://www.somatik.be
> Microsoft gives you windows, Linux gives you the whole house.
>
> ---------------------------------------------------------------------
> 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]