Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

From AWT to SWING

  Asked By: Cory    Date: May 27    Category: Java    Views: 1247
  


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!! public
String[] getItem(int index) { String arr[] =
null; // = new
String[headerDimensions.length]; int len = 0; String ls =
listBox.getItem(index); if (ls != null) { arr = new
String[headerDimensions.length]; for (int count = 0; count <
headerDimensions.length; count++) { arr[count] =
ls.substring(len,
len+headerDimensions[count]-1); arr[count]= arr[count].trim(); len
+=
headerDimensions[count]; } } return arr; }
/** Return the number
of items currently in the
list. */ public int getItemCount() { //return
listBox.getItemCount(); int a =0; return a; } /** If
an
item is selected, remove it from the list
box. */ public void deleteSelectedItem() { /** if
(listBox.getSelectedItem() !=
null) { listBox.remove(listBox.getSelectedItem()); } */
} /** Render the list box empty. */ public void
clear() { listBox.removeAll(); }

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Isaac Williams     Answered On: May 27

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
www.phrantic.com/scoop/tocadv.htm<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

 
Answer #2    Answered By: Dennis Hayes     Answered On: May 27

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>http://www.crosslogic.com

 
Didn't find what you were looking for? Find more on From AWT to SWING Or get search suggestion and latest updates.




Tagged: