-
Bug
-
Resolution: Fixed
-
P2
-
1.0
-
1.0.2
-
x86
-
windows_nt
-
Verified
Win 32 only: list.clear() does not clear all items from list.
Note: see workaround
Steps to reproduce
Compile the following code
run java ListTest
Press <Change List>
/* tests the list stuff */
import java.awt.*;
import java.applet.Applet;
public class ListTest extends Applet
{
public final String ChangeList = "Change List";
public final String GetSelected = "Get Selected Index";
List list;
Label getVisLabel;
Label getSelectLabel;
Label makeVisLabel;
Label listSizeLabel;
public void init()
{
setLayout( new BorderLayout() );
list = new List(3, false);
list.addItem("One");
list.addItem("Two");
list.addItem("Three");
list.addItem("Four");
list.addItem("Five");
list.addItem("Six");
Panel p2 = new Panel();
p2.add(list);
Panel panel = new Panel();
panel.setLayout( new GridLayout(4, 2) );
panel.add( new Button("makeVisible") );
panel.add( makeVisLabel = new Label() );
panel.add( new Button("getVisibleIndex") );
panel.add( getVisLabel = new Label("Nothing") );
panel.add( new Button(GetSelected) );
panel.add( getSelectLabel = new Label("Nothing") );
panel.add( new Button(ChangeList) );
panel.add( listSizeLabel = new Label() );
updateLabels();
add("West", panel);
add("Center", p2);
resize(400, 400);
}
public void updateLabels()
{
makeVisLabel.setText( Integer.toString( list.countItems() -1 ) );
listSizeLabel.setText( Integer.toString( list.countItems() ) );
}
public boolean action(Event evt, Object obj)
{
if (evt.target instanceof Button)
{
String text = (String) obj;
if ( text.equals("makeVisible") )
list.makeVisible(list.countItems() - 1);
else if ( text.equals("getVisibleIndex") )
getVisLabel.setText( Integer.toString( list.getVisibleIndex() ) );
else if ( text.equals(GetSelected) )
getSelectLabel.setText( Integer.toString( list.getSelectedIndex() ) );
else if ( text.equals(ChangeList) )
changeList();
else
return false;
updateLabels();
return true;
} // end if button
return super.action(evt, obj);
}
public void changeList()
{
// local variables
int listCount = list.countItems();
list.clear(); // fails on win32
// list.delItems(0, listCount - 1); // workaround
for(int i = 0; i < listCount; ++i)
list.addItem( Integer.toString(i) );
}
public static void main(String args[])
{
AppletFrame.startApplet("ListTest", "List Test", args);
}
}
/* Generic Applet to Application Frame
* @(#)AppletFrame.java 1.4 12/02/95 15:28:07
* @author Kevin A. Smith
*
*/
import java.awt.Frame;
import java.awt.Event;
import java.awt.Dimension;
import java.applet.Applet;
// Applet to Application Frame window
class AppletFrame extends Frame
{
public static void startApplet(String className,
String title,
String args[])
{
// local variables
Applet a;
Dimension appletSize;
try
{
// create an instance of your applet class
a = (Applet) Class.forName(className).newInstance();
}
catch (ClassNotFoundException e) { return; }
catch (InstantiationException e) { return; }
catch (IllegalAccessException e) { return; }
// initialize the applet
a.init();
a.start();
// create new application frame window
AppletFrame f = new AppletFrame(title);
// add applet to frame window
f.add("Center", a);
// resize frame window to fit applet
// assumes that the applet sets its own size
// otherwise, you should set a specific size here.
appletSize = a.size();
f.pack();
f.resize(appletSize);
// show the window
f.show();
} // end startApplet()
// constructor needed to pass window title to class Frame
public AppletFrame(String name)
{
// call java.awt.Frame(String) constructor
super(name);
}
// needed to allow window close
public boolean handleEvent(Event e)
{
// Window Destroy event
if (e.id == Event.WINDOW_DESTROY)
{
// exit the program
System.exit(0);
return true;
}
// it's good form to let the super class look at any
// unhandled events
return super.handleEvent(e);
} // end handleEvent()
} // end class AppletFrame
Note: see workaround
Steps to reproduce
Compile the following code
run java ListTest
Press <Change List>
/* tests the list stuff */
import java.awt.*;
import java.applet.Applet;
public class ListTest extends Applet
{
public final String ChangeList = "Change List";
public final String GetSelected = "Get Selected Index";
List list;
Label getVisLabel;
Label getSelectLabel;
Label makeVisLabel;
Label listSizeLabel;
public void init()
{
setLayout( new BorderLayout() );
list = new List(3, false);
list.addItem("One");
list.addItem("Two");
list.addItem("Three");
list.addItem("Four");
list.addItem("Five");
list.addItem("Six");
Panel p2 = new Panel();
p2.add(list);
Panel panel = new Panel();
panel.setLayout( new GridLayout(4, 2) );
panel.add( new Button("makeVisible") );
panel.add( makeVisLabel = new Label() );
panel.add( new Button("getVisibleIndex") );
panel.add( getVisLabel = new Label("Nothing") );
panel.add( new Button(GetSelected) );
panel.add( getSelectLabel = new Label("Nothing") );
panel.add( new Button(ChangeList) );
panel.add( listSizeLabel = new Label() );
updateLabels();
add("West", panel);
add("Center", p2);
resize(400, 400);
}
public void updateLabels()
{
makeVisLabel.setText( Integer.toString( list.countItems() -1 ) );
listSizeLabel.setText( Integer.toString( list.countItems() ) );
}
public boolean action(Event evt, Object obj)
{
if (evt.target instanceof Button)
{
String text = (String) obj;
if ( text.equals("makeVisible") )
list.makeVisible(list.countItems() - 1);
else if ( text.equals("getVisibleIndex") )
getVisLabel.setText( Integer.toString( list.getVisibleIndex() ) );
else if ( text.equals(GetSelected) )
getSelectLabel.setText( Integer.toString( list.getSelectedIndex() ) );
else if ( text.equals(ChangeList) )
changeList();
else
return false;
updateLabels();
return true;
} // end if button
return super.action(evt, obj);
}
public void changeList()
{
// local variables
int listCount = list.countItems();
list.clear(); // fails on win32
// list.delItems(0, listCount - 1); // workaround
for(int i = 0; i < listCount; ++i)
list.addItem( Integer.toString(i) );
}
public static void main(String args[])
{
AppletFrame.startApplet("ListTest", "List Test", args);
}
}
/* Generic Applet to Application Frame
* @(#)AppletFrame.java 1.4 12/02/95 15:28:07
* @author Kevin A. Smith
*
*/
import java.awt.Frame;
import java.awt.Event;
import java.awt.Dimension;
import java.applet.Applet;
// Applet to Application Frame window
class AppletFrame extends Frame
{
public static void startApplet(String className,
String title,
String args[])
{
// local variables
Applet a;
Dimension appletSize;
try
{
// create an instance of your applet class
a = (Applet) Class.forName(className).newInstance();
}
catch (ClassNotFoundException e) { return; }
catch (InstantiationException e) { return; }
catch (IllegalAccessException e) { return; }
// initialize the applet
a.init();
a.start();
// create new application frame window
AppletFrame f = new AppletFrame(title);
// add applet to frame window
f.add("Center", a);
// resize frame window to fit applet
// assumes that the applet sets its own size
// otherwise, you should set a specific size here.
appletSize = a.size();
f.pack();
f.resize(appletSize);
// show the window
f.show();
} // end startApplet()
// constructor needed to pass window title to class Frame
public AppletFrame(String name)
{
// call java.awt.Frame(String) constructor
super(name);
}
// needed to allow window close
public boolean handleEvent(Event e)
{
// Window Destroy event
if (e.id == Event.WINDOW_DESTROY)
{
// exit the program
System.exit(0);
return true;
}
// it's good form to let the super class look at any
// unhandled events
return super.handleEvent(e);
} // end handleEvent()
} // end class AppletFrame