|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--waba.ui.Control | +--waba.ui.Container | +--waba.ui.ListBox
ListBox is a simple implementation of a Listbox. You can use the up/down keys to scroll and enter the first letter of an item to select it.
Note: the color used in the setBackground method will be used in the scrollbar only. The background color of the control will be a lighter version of the given color.
Here is an example showing how it can be used:
import waba.ui.*; public class MyProgram extends MainWindow { ListBox lb; public void onStart() { lb = new ListBox(); add(lb); lb.add(new String[]{"Daniel","Jenny","Helge","Sandra"}); lb.add("Marc"); // you may set the rect by using PREFERRED only after the items were added. lb.setRect(LEFT,TOP,PREFERRED,PREFERRED); // use control's preferred width based on the size of the elements } public void onEvent(Event event) { switch (event.type) { case ControlEvent.PRESSED: if (event.target == lb) Object element = lb.getSelectedItem(); // in most cases, this is just a String and may be casted to such } } }The first item has index 0.
Field Summary | |
protected int |
btnX
|
protected int |
itemCount
|
protected Vector |
items
|
protected int |
offset
|
protected ScrollBar |
sbar
|
protected int |
selectedIndex
|
protected boolean |
simpleBorder
|
protected int |
visibleItems
|
Fields inherited from class waba.ui.Container |
BORDER_LOWERED,
BORDER_NONE,
BORDER_RAISED,
BORDER_SIMPLE,
children,
lastH,
lastW,
lastX,
lastY,
parentWindow,
tail |
Fields inherited from class waba.ui.Control |
AFTER,
appId,
asContainer,
asWindow,
backColor,
backDis,
BEFORE,
BOTTOM,
CENTER,
enabled,
FILL,
FIT,
fm,
fmH,
focusLess,
font,
foreColor,
foreDis,
height,
LEFT,
parent,
PREFERRED,
RANGE,
RIGHT,
SAME,
TOP,
visible,
width,
x,
x2,
y,
y2 |
Constructor Summary | |
ListBox()
Creates an empty Listbox. |
|
ListBox(Object[] items)
Creates a Listbox with the given items. |
Method Summary | |
void |
add(Control control)
do nothing |
void |
add(Object item)
Adds an Object to the Listbox |
void |
add(Object[] moreItems)
Adds an array of Objects to the Listbox |
protected void |
drawCursor(Graphics g,
int sel,
boolean on)
|
protected void |
drawItem(Graphics g,
int index,
int dx,
int dy)
You can extend ListBox and overide this method to draw the items |
protected void |
find(char c)
Searches this ListBox for an item with the first letter matching the given char. |
Object |
getItemAt(int i)
Get the Object at the given Index |
Object[] |
getItems()
Returns all items in this ListBox. |
protected int |
getItemWidth(int index)
Returns the width of the given item index with the current fontmetrics. |
int |
getPreferredHeight()
returns the number of items multiplied by the font metrics height |
int |
getPreferredWidth()
returns the preferred width, ie, the size of the largest item plus 20. |
int |
getSelectedIndex()
Returns the position of the selected item of the Listbox or -1 if the listbox has no selected index yet. |
Object |
getSelectedItem()
Returns the selected item of the Listbox or an empty Object if none is selected |
int |
indexOf(Object name)
Returns the index of the item specified by the name |
void |
insert(Object item,
int index)
Adds an Object to the Listbox at the given index |
protected void |
onBoundsChanged()
Called after an setRect. |
protected void |
onColorsChanged(boolean colorsChanged)
Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. |
void |
onEvent(Event event)
Called to process key, pen, control and other posted events. |
void |
onPaint(Graphics g)
Draws the border (if any). |
void |
qsort()
Sorts the elements of this ListBox. |
void |
remove(Control control)
do nothing |
void |
remove(int itemIndex)
Removes the given index from the Listbox |
void |
remove(Object item)
Removes an Object from the Listbox |
void |
removeAll()
Empties this ListBox, setting all elements of the array to null
so they can be garbage collected.
|
void |
select(int i)
Select an item and scroll to it if necessary. |
void |
setCursorColor(Color color)
Sets the cursor color for this ListBox. |
void |
setEnabled(boolean enabled)
sets if this container and all childrens can or not accept events |
void |
setItemAt(int i,
Object s)
Sets the Object at the given Index, starting from 0 |
void |
setSimpleBorder(boolean simpleBorder)
Sets the border of the listbox to be not 3d if flag is true. |
int |
size()
Returns the number of items |
Methods inherited from class waba.ui.Container |
add,
add,
broadcastEvent,
findChild,
getChildren,
getClientRect,
onStart,
paintChildren,
setBorderStyle |
Methods inherited from class waba.ui.Control |
addTimer,
contains,
createGraphics,
getAbsoluteRect,
getBackColor,
getFont,
getFontMetrics,
getForeColor,
getNext,
getParent,
getParentWindow,
getPos,
getRect,
getSize,
isDisplayed,
isEnabled,
isVisible,
onFontChanged,
onWindowPaintFinished,
postEvent,
removeTimer,
repaint,
repaintNow,
requestFocus,
setBackColor,
setBackForeColors,
setFocusLess,
setFont,
setForeColor,
setRect,
setRect,
setRect,
setVisible |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
toString,
wait,
wait |
Field Detail |
protected Vector items
protected int offset
protected int selectedIndex
protected int itemCount
protected int visibleItems
protected int btnX
protected ScrollBar sbar
protected boolean simpleBorder
Constructor Detail |
public ListBox()
public ListBox(Object[] items)
Method Detail |
public void add(Object[] moreItems)
public void add(Object item)
public void insert(Object item, int index)
public void removeAll()
null
so they can be garbage collected.
Attention! If you used the same object array
to initialize two ListBoxes (or ComboBoxes), this method will null both ListBoxes
('cos they use the same array reference),
and you'll get a null pointer exception!public void remove(int itemIndex)
public void remove(Object item)
public void setItemAt(int i, Object s)
public Object getItemAt(int i)
public Object getSelectedItem()
public int getSelectedIndex()
public Object[] getItems()
public int indexOf(Object name)
public void select(int i)
public int size()
public void add(Control control)
public void remove(Control control)
public int getPreferredWidth()
public int getPreferredHeight()
protected void onBoundsChanged()
protected void find(char c)
public void onEvent(Event event)
event
- the event to processEvent
,
KeyEvent
,
PenEvent
public void setEnabled(boolean enabled)
protected void onColorsChanged(boolean colorsChanged)
public void onPaint(Graphics g)
super.onPaint(g);
, or the border will not be drawn.g
- the graphics object for drawingGraphics
public void setCursorColor(Color color)
protected void drawItem(Graphics g, int index, int dx, int dy)
protected int getItemWidth(int index)
protected void drawCursor(Graphics g, int sel, boolean on)
public void setSimpleBorder(boolean simpleBorder)
public void qsort()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |