Skip to main content

Combo box problem

4 replies [Last post]
viator123
Offline
Joined: 2009-03-12

Hi,

I have a problem with comboxes (actually seems generic for any list). I'm trying to navigate through a tree structure representing a taxonomy. When you select an item it is either a leaf node or has a lower level of selection required. When a parent node is selected I update the model with the children of the parent for the user to select the next level.

Everything works as expected unless at any point the list doesn't fit on the screen. It successfully scrolls down the list and the selection works fine in that the children are then displayed in the combo. However none of the items are then selectable i.e. my selection listener never gets fired. The only difference from the working scenario is selecting a parent object which was initially off the screen.

Thanks in advance.

Reply viewing options

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

Hi,
I have no idea what you are trying to do here.
Feel free to open an issue with a readable working test case if you
feel we are doing something wrong, we are however quite different
from Swing and working in Swing is no indication to working in LWUIT.

> Hi,
>
> I also assume this is related to scrollability. Firstly I'll point
> out I'm trying to port some code from a much larger Swing
> application to LWUIT so I know the underlying design is fine so its
> to do with differences between Swing and LWUIT.
>
> This is a simplified version of what I really intend to build with
> some dependent classes missing e.g. my list model has been removed
> to show what doesn't work with the DefaultListModel
>
> final public class SightingForm extends Form {
> public CheckList currentList;
>
> private TaxonomyCombo taxaCombo;
> private List sightingList = new List(new SightingListModel());
>
> public SightingForm() {
> super("Record Sightings");
> final Hashtable availChecklists = new Hashtable();
> currentList = (CheckList) new clid18();
> availChecklists.put(currentList.getName(), currentList);
>
> taxaCombo = new TaxonomyCombo(currentList,this);
> setScrollable(false);
>
> this.addComponent(taxaCombo);
> }
>
> public void addSpecies(TaxonomyNode node) {
> System.out.println("selected species " + node);
> }
> }
>
> public final class TaxonomyCombo extends ComboBox implements
> SelectionListener {
>
> private CheckList list;
> private SightingForm form;
>
> public TaxonomyCombo(CheckList l, SightingForm f) {
> list = l;
> form = f;
> list.init();
> setModel(new DefaultListModel((Vector)list.childrenMap.get(new
> Integer(list.getBaseID()))));
> setFixedSelection(FIXED_NONE_CYCLIC);
> addSelectionListener(this);
> }
>
> public void setModel(Vector v) {
> removeSelectionListener(this);
> setModel(new DefaultListModel(v));
> addSelectionListener(this);
> }
> public void selectionChanged(int oldSelected, int newSelected) {
> if (newSelected != -1) {
> final TaxonomyNode node = (TaxonomyNode) getSelectedItem();
> final Vector children = (Vector) list.childrenMap.get(new Integer
> (node.getID()));
> if (children != null) {
> removeSelectionListener(this);
> setModel(new DefaultListModel(children));
> addSelectionListener(this);
> } else {
> form.addSpecies(node);
> }
> }
> }
>
> }
>
> The 'real' code doesn't instantiate new models each time and I've
> ran with the above code and it works the same as the code I want to
> use. For reference the CheckList consists of two main structures,
> firstly a Hashtable that maps an ID to a TaxonomyNode (which is
> basically a common name, latin name for a bird plus its ID and its
> parent ID in the hierachy) along with a Vector for each taxonomy ID
> which contains all children of that ID. Code for all this can be
> posted if it will help.
>
> I've tried all sorts of layout and scroll settings in the Form but
> can't make it work.
>
> BTW much easier in my Swing application than this due to a lot more
> collections than just Hashtable and Vector i.e. neither are used!
>
> Thanks
> Mike
> [Message sent by forum member 'viator123' (viator123)]
>
> http://forums.java.net/jive/thread.jspa?messageID=337974
>
> ---------------------------------------------------------------------
> 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/
https://lwuit.dev.java.net/faq.html

[att1.html]

Shai Almog

Hi,
I assume this is related to the scrollability of the nested container
but its really hard to understand your issue. Please provide readable
code and a screenshot to illustrate that.

> Hi,
>
> I have a problem with comboxes (actually seems generic for any
> list). I'm trying to navigate through a tree structure representing
> a taxonomy. When you select an item it is either a leaf node or has
> a lower level of selection required. When a parent node is selected
> I update the model with the children of the parent for the user to
> select the next level.
>
> Everything works as expected unless at any point the list doesn't
> fit on the screen. It successfully scrolls down the list and the
> selection works fine in that the children are then displayed in the
> combo. However none of the items are then selectable i.e. my
> selection listener never gets fired. The only difference from the
> working scenario is selecting a parent object which was initially
> off the screen.
>
> Thanks in advance.
> [Message sent by forum member 'viator123' (viator123)]
>
> http://forums.java.net/jive/thread.jspa?messageID=337648
>
> ---------------------------------------------------------------------
> 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/
https://lwuit.dev.java.net/faq.html

[att1.html]

viator123
Offline
Joined: 2009-03-12

Hi,

I also assume this is related to scrollability. Firstly I'll point out I'm trying to port some code from a much larger Swing application to LWUIT so I know the underlying design is fine so its to do with differences between Swing and LWUIT.

This is a simplified version of what I really intend to build with some dependent classes missing e.g. my list model has been removed to show what doesn't work with the DefaultListModel

final public class SightingForm extends Form {
public CheckList currentList;

private TaxonomyCombo taxaCombo;
private List sightingList = new List(new SightingListModel());

public SightingForm() {
super("Record Sightings");
final Hashtable availChecklists = new Hashtable();
currentList = (CheckList) new clid18();
availChecklists.put(currentList.getName(), currentList);

taxaCombo = new TaxonomyCombo(currentList,this);
setScrollable(false);

this.addComponent(taxaCombo);
}

public void addSpecies(TaxonomyNode node) {
System.out.println("selected species " + node);
}
}

public final class TaxonomyCombo extends ComboBox implements SelectionListener {

private CheckList list;
private SightingForm form;

public TaxonomyCombo(CheckList l, SightingForm f) {
list = l;
form = f;
list.init();
setModel(new DefaultListModel((Vector)list.childrenMap.get(new Integer(list.getBaseID()))));
setFixedSelection(FIXED_NONE_CYCLIC);
addSelectionListener(this);
}

public void setModel(Vector v) {
removeSelectionListener(this);
setModel(new DefaultListModel(v));
addSelectionListener(this);
}
public void selectionChanged(int oldSelected, int newSelected) {
if (newSelected != -1) {
final TaxonomyNode node = (TaxonomyNode) getSelectedItem();
final Vector children = (Vector) list.childrenMap.get(new Integer(node.getID()));
if (children != null) {
removeSelectionListener(this);
setModel(new DefaultListModel(children));
addSelectionListener(this);
} else {
form.addSpecies(node);
}
}
}

}

The 'real' code doesn't instantiate new models each time and I've ran with the above code and it works the same as the code I want to use. For reference the CheckList consists of two main structures, firstly a Hashtable that maps an ID to a TaxonomyNode (which is basically a common name, latin name for a bird plus its ID and its parent ID in the hierachy) along with a Vector for each taxonomy ID which contains all children of that ID. Code for all this can be posted if it will help.

I've tried all sorts of layout and scroll settings in the Form but can't make it work.

BTW much easier in my Swing application than this due to a lot more collections than just Hashtable and Vector i.e. neither are used!

Thanks
Mike

viator123
Offline
Joined: 2009-03-12

With this code if I select a parent node which doesn't need to be scrolled to to click on then then children are displayed and they are selectable - and either the next level list is displayed in the combo or the println reports the leaf node selected.

If I scroll through a list below the original screen size then the children of the selected node are displayed correctly e.g. I have 100 nodes I select the 50th with 5 children then the 5 node are displayed in the resultant popup. However no matter what or where I click nothing registers in the Selection listener - the only option is to click "Exit" (which still works so the app isn't hung) from the base MIDlet class.

Thanks
Mike