02-05-2010 09:03 AM
<First post - be gentle!> I have seen similar postings but not enough information to go on. I'm new to b'berry and java too, this is my first App, and it involves Notifications, storage of options, HTTP requests, XML and browser integration, it's been a steep learning curve!
I have a ListField with a ListFieldCallback, which draws some text into the list members. When the wheel is used to select items, the background is blue but the foreground unchanged, rendering the text nearly illegible. I would like either the text to be inverted in colour, or the blue background to be an outline rectangle (preferred). I think the answer lies somewhere to do with focusRect and getCallback but I don't know what to do. Ideally, I'd like to change code in the callback class 'drawListRow()', but I suspect things are not that simple!
My code looks like (sorry I may have put too much in, I wanted to know which bits to change):
...
final class SMobile extends UiApplication
{
...
private ListCallback myCallback;
private ListField myList;
public static void main(String[] args)
{
...
SMobile theApp = new SMobile( true);
theApp.enterEventDispatcher();
...
}
...
private SMobile( boolean runmode)
{
...
myList = new ListField();
myCallback = new ListCallback();
myList.setCallback(myCallback);
myCallback.erase();
_mainScreen.add(myList);
...
pushScreen(_mainScreen);
}
...
private static class ListEntry {
public String s = "";
public String t = "";
public String f = "";
public String st = "";
public String m = "";
}
private static class ListCallback implements ListFieldCallback {
private Vector listElements = new Vector();
public void drawListRow(ListField list, Graphics g,
int index, int y, int w) {
ListEntry _entry = (ListEntry)listElements.elementAt(index);
if ( _entry.st.indexOf("U") != -1)
{
g.setColor( Color.DARKRED);
}
else
{
g.setColor( Color.DARKGREEN);
}
Font _font = g.getFont();
int size = (_font.getHeight() ) / 2;
_font = _font.derive(0, size, Ui.UNITS_px);
g.setFont( _font);
g.drawText(_entry.s.concat(", ").concat(_entry.t).concat(",").concat(_entry.st),
0, y+1, (int)( DrawStyle.ELLIPSIS | DrawStyle.LEFT ), w);
g.setColor( Color.BLACK);
g.drawText(_entry.f.concat(", ").concat(_entry.m),
10, y + _font.getHeight()-1,
(int)( DrawStyle.ELLIPSIS | DrawStyle.LEFT ), w);
}
public Object get(ListField list, int index) {
return listElements.elementAt(index);
}
public int indexOfList(ListField list, String p, int s) {
return -1; //Not implemented, as we have an object in the Vector, not a string
}
public int getPreferredWidth(ListField list) {
return Display.getWidth();
}
public void insert(ListEntry toInsert, int index) {
listElements.insertElementAt(toInsert, index);
}
public void erase() {
listElements.removeAllElements();
}
}
...
}
Please can anyone advise?
Thanks.
Steve
Solved! Go to Solution.
02-09-2010 03:26 PM
This example should get you going in the right direction....
How To - Create a colour ListField
Article Number: DB-00472
02-22-2010 10:39 AM
Thanks Mark,
I ended up using a similar method with a twist. I drew a background rectangle a little smaller than the list element, so the blue selection box turns into a blue outline, and coloured items of foreground are not obscured by it:
...
public void drawListRow(ListField list, Graphics g,
int index, int y, int w) {
ListEntry _entry = (ListEntry)listElements.elementAt(index);
//Draw background rectangle to replace dk blue selection rectangle with outline only
g.setColor( Color.WHITESMOKE); //Pale but not white
int h = list.getRowHeight();
g.fillRect( 2, y+2, w-4, h-4);
...
Steve