freelanceprogrammers.org Forum Index » Java

From AWT to SWING


View user's profile Post To page top
chantwdavid Posted: Fri Feb 08, 2002 8:42 am


Joined: 08 Feb 2002

Posts: 4
From AWT to SWING
I searched from the API, and looking for the
method of Class "JList" that equal to the Class " List"
where appeared in the old java program. I am trying to
replace List with JList, Just only few methods I cannot
change it. And the remaining old code is listing. Can
Someone help me to change it.Please!!<br><br><br> public
String[] getItem(int index)<br> {<br><br> String arr[] =
null; // = new
String[headerDimensions.length];<br> int len = 0;<br> String ls =
listBox.getItem(index);<br><br> if (ls != null)<br> {<br> arr = new
String[headerDimensions.length];<br> for (int count = 0; count &lt;
headerDimensions.length; count++)<br> {<br> arr[count] =
ls.substring(len,
len+headerDimensions[count]-1);<br> arr[count]= arr[count].trim();<br> len
+=
headerDimensions[count];<br> }<br><br> }<br> return arr;<br><br> }<br><br>
/**<br> Return the number
of items currently in the
list.<br> */<br><br> public int getItemCount()<br> {<br><br> //return
listBox.getItemCount();<br> int a =0;<br> return a;<br> }<br><br> /**<br> If
an
item is selected, remove it from the list
box.<br> */<br><br> public void deleteSelectedItem()<br> {<br> /**<br> if
(listBox.getSelectedItem() !=
null)<br> {<br> listBox.remove(listBox.getSelectedItem());<br> }<br> */<br>
}<br><br> /**<br> Render the list box empty.<br> */<br><br> public void
clear()<br> {<br> listBox.removeAll();<br> }
Reply with quote
Send private message
View user's profile Post To page top
epenak Posted: Fri Feb 08, 2002 9:58 pm


Joined: 31 Jan 2002

Posts: 39
From AWT to SWING
I was floored by the change from AWT`s List box
to Swing`s JList, also, when I first encountered
it.<br><br>Sun actually implemented Object Oriented design
principles because they saw that there was a whole lot more
complicated uses for the listbox than a simple component
could handle.<br><br>So they created the JList Swing
component to be a manager and a delegator. It delegates the
rendering to a cell renderer so that you can compose each
cell using your own rendering class. It delegates the
management of the list to a list model so that the JList
itself doesn`t have to add, update and delete individual
cells. And it delegates the changes of content and
selection to event listeners. This explanation may not be
entirely accurate but it is close enough to send you
scurrying off to find more background.<br><br>There is a
bunch of detail here--way too much to include in this
post. So I will refer you to my favorite book on the
subject: Graphic Java 2 Mastering the JFC by David M.
Geary. I am sure there are other books but this one
seems to cover everything on Swing. It is volume 2 in
the Graphic Java Series. Other volumes cover AWT, and
advanced graphical topics.<br><br>If you cannot get your
hands on a copy, visit Richard Baldwin`s tutorials for
some hands-on coding at
<a href=http://www.phrantic.com/scoop/tocadv.htm
target=new>http://www.phrantic.com/scoop/tocadv.htm</a><br>look for the advanced
tutorials 209-212. There are
lots of other topics to explore here. When I want to
review a topic, I usually visit here.<br><br>From
Geary`s book:<br>AWT.List Method ....... JList equivalent
(JList list)<br>int getItemCount ......
list.getModel.getSize()<br>void remove(int) ...... void
DefaultListModel.removeElementAt(int)<br>void removeAll() ...... void
setListData(null)<br>String getItem(int) ...
lit.getModel.getItemAt(int)<br><br>There are other equivalents but these match
your
request.<br><br>JList compares to JTree in flexibility and complexity
IMHO.<br><br>epenak
Reply with quote
Send private message
View user's profile Post To page top
mcconnell_stephen Posted: Fri Feb 08, 2002 10:06 pm


Joined: 01 Feb 2002

Posts: 73
From AWT to SWING
Cool link and great explaination. I haven`t been
doing much GUI programming lately, so a place where I
can grab code to review for study is great. And a
little discussion on the design philosophy behind Swing
is good.<br><br>I`ve been working with some of the
people that helped write the Visual Composition Editor
for VAJ; and they have some interesting insites into
Swing, also.<br><br>I also agree with YHO.... JTable is
also a REAALL complex API that has tons of
flexibilty.<br><br>O`Reily Press has a good book on Swing with lots of good
examples that helps you through the
complexity.<br><br>Stephen McConnell<br><a href=http://www.crosslogic.com
target=new>http://www.crosslogic.com</a>
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help