🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
4 messages
4 total messages Started by John Meyer Thu, 19 Jan 2006 00:31
Adding a string to a JList
#94
Author: John Meyer
Date: Thu, 19 Jan 2006 00:31
2 lines
858 bytes
Hi,
How do I add a string to a JList?
Re: Adding a string to a JList
#95
Author: Paul Furbacher [TeamB]
Date: Thu, 19 Jan 2006 04:20
38 lines
2196 bytes
John Meyer wrote:

> How do I add a string to a JList?

As with all Swing components, get the underlying
model.  In the case of a JList, the "concrete"
underlying model is DefaultListModel, so when you
ask

   myList.getModel();

you have to typecast the returned value to DefaultListModel
in order to use the methods which add an object to the
list.  Note that the list may not contain just String
object, but any object which has a "toString()" method.


It may be time to read the tutorials on Swing at the
java.sun.com Web site, or better yet, get a good book
on Swing.  It's complex, so there's no better way
to invest in your career than to buy a good book now
and then.


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://info.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Re: Adding a string to a JList
#96
Author: Paul Furbacher [TeamB]
Date: Thu, 19 Jan 2006 04:28
39 lines
2367 bytes
Paul Furbacher [TeamB] wrote:

> [...]  DefaultListModel [...]

To add to what I just wrote, you should be using
the "drill down" feature of JBuilder to your
advantage.  Put the cursor anywhere in the word
"JList" in your source file, hit Control-return,
and you are looking at the source for JList.
 From there, use the Structure Pane to flip to
the "getModel()" method.  Note that it returns
an interface, ListModel.  Search the JList.java
file in your editor for "listmodel" and read the
discussions.  Or flip to the "Doc" tab, and read
them there in more nicely rendered HTML.  See
the links to the various tutorials and articles.
One in particular is well-suited to answering
your question.

Finally, drill down into DefaultListModel, and take
that lesson to the bank by using the drill down
technique to become more familiar with any API
which comes with source code.


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://info.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Re: Adding a string to a JList
#107
Author: John Meyer
Date: Wed, 01 Feb 2006 17:41
41 lines
2494 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Paul Furbacher [TeamB] wrote:
> Paul Furbacher [TeamB] wrote:
> 
>> [...]  DefaultListModel [...]
> 
> To add to what I just wrote, you should be using
> the "drill down" feature of JBuilder to your
> advantage.  Put the cursor anywhere in the word
> "JList" in your source file, hit Control-return,
> and you are looking at the source for JList.
> From there, use the Structure Pane to flip to
> the "getModel()" method.  Note that it returns
> an interface, ListModel.  Search the JList.java
> file in your editor for "listmodel" and read the
> discussions.  Or flip to the "Doc" tab, and read
> them there in more nicely rendered HTML.  See
> the links to the various tutorials and articles.
> One in particular is well-suited to answering
> your question.
> 
> Finally, drill down into DefaultListModel, and take
> that lesson to the bank by using the drill down
> technique to become more familiar with any API
> which comes with source code.


Thanks.
I went through the whole help file, and some of the Java, and found the
answer, namely, adding the objects through the DefaultListModel and not
the JList directly.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFD4PLdj60GAoLuoDkRAnTKAKCROcpcZwWEIS4TrKRQKcuGmi/6hwCfSdVp
t7nqeg6n/JIVDEL9t8VtqXk=
=SmKa
-----END PGP SIGNATURE-----
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads