Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1079
| From | Thomas Jensen <lianergoist@sejlgarnet.dk> |
|---|---|
| Subject | Re: J2ME - List and Font |
| Newsgroups | comp.lang.java.help |
| References | <pan.2011.09.20.06.42.08@sejlgarnet.dk> <324i779g6elejq61hfb7f7luvgu3uti2j4@4ax.com> |
| Message-ID | <pan.2011.09.22.08.36.25@sejlgarnet.dk> (permalink) |
| Date | 2011-09-22 08:36 +0000 |
| Organization | SunSITE.dk - Supporting Open source |
On Tue, 20 Sep 2011 15:18:58 -0700, Roedy Green wrote:
>>msglist.setFont(0, f);
> see http://mindprod.com/jgloss/sscce.html
Good point.
> I don't see how this could compile. Your MyMsgList class has no setFont
> method.
>
I think I should have been more clear about the fact, that this is j2me
code. The myListClass is extending the List class from
javax.microedition.lcdui.* and setFont() is a method to List.
http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/
List.html
I have uploaded the code to www.tj-software.dk/j2me/sms.zip.
And, I have found a solution to my problem, but I still don't understand
my original problem, so if someone can enlighten me, I would much
appreaciate.
So, if I do this:
Font f = Font.getFont(0, 0, Font.SIZE_LARGE);
msglist = new myListClass("messages");
/* appends elements to list here */
for (int i=0;i<msglist.size();i++) {
msglist.setFont(i, f);
}
msglist.setCommandListener(this);
display.setCurrent(msglist);
then will all element in the list be with large font. That's good and
proves it's working.
But if I want to make my list class do the job of making the font large,
I (did) think I have to do something like this.
public final class myListClass extends List {
rec_class recs;
Vector data;
Font f = Font.getFont(0, 0, Font.SIZE_LARGE);
public myListClass (String lname)
{
super (lname, Choice.IMPLICIT);
recs = new rec_class(lname);
myRebuild();
}
public void myRebuild () {
deleteAll();
data = recs.getrecords();
int i = 0;
for (Enumeration e = data.elements(); e.hasMoreElements(); ) {
append((String)e.nextElement(), null);
setFont(i++, f);
}
}
}
It compile, but when running, it throws and exception -
"java.lang.ArrayIndexOutOfBoundsException". I expect the array is the
lists array of elements. I don't understand why there is a problem,
because after appending an element, I think it should be possible to use
to it.
But I found a solution -
for (Enumeration e = data.elements(); e.hasMoreElements(); ) {
append((String)e.nextElement(), null);
//setFont(i++, f);
}
for (int i=0;i<size();i++) {
setFont(i, f);
}
ehhh, what? I have no idea why, but it works.
--
Thomas Jensen, Denmark
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
J2ME - List and Font Thomas Jensen <lianergoist@sejlgarnet.dk> - 2011-09-20 06:42 +0000
Re: J2ME - List and Font "John B. Matthews" <nospam@nospam.invalid> - 2011-09-20 14:01 -0400
Re: J2ME - List and Font Roedy Green <see_website@mindprod.com.invalid> - 2011-09-20 15:13 -0700
Re: J2ME - List and Font Roedy Green <see_website@mindprod.com.invalid> - 2011-09-20 15:18 -0700
Re: J2ME - List and Font Thomas Jensen <lianergoist@sejlgarnet.dk> - 2011-09-22 08:36 +0000
Re: J2ME - List and Font Thomas Jensen <lianergoist@sejlgarnet.dk> - 2011-09-22 10:36 +0000
Re: J2ME - List and Font Roedy Green <see_website@mindprod.com.invalid> - 2011-09-22 12:15 -0700
Re: J2ME - List and Font Roedy Green <see_website@mindprod.com.invalid> - 2011-09-22 12:17 -0700
csiph-web