-
Bug
-
Resolution: Fixed
-
P3
-
1.0
-
None
-
1.0beta2
-
x86
-
windows_nt
-
Verified
###@###.###
All platforms: awt.List.getVisibleIndex() always returns -1. It should return the
index of the last item in the list. (Docs say it is the last value set by
awt.List.makeVisible(), which it isn't doing either.)
Steps to reproduce
Compile and run the attached code
Press <makeVisible>
// note item Six in the list should now be visible
Press <getVisibleIndex>
// Note: the value next to this should be 5
/* tests the list stuff */
import java.awt.*;
import java.applet.Applet;
public class ListTest extends Applet
{
List list;
Label label;
Label label1;
public void init()
{
Panel panel = new Panel();
list = new List(4, false);
list.addItem("One");
list.addItem("Two");
list.addItem("Three");
list.addItem("Four");
list.addItem("Five");
list.addItem("Six");
panel.add( new Button("makeVisible") );
panel.add( new Button("getVisibleIndex") );
panel.add( label = new Label("Nothing") );
panel.add( new Button("getSelectedIndex") );
panel.add( label1 = new Label("Nothing") );
add(panel);
add(list);
resize(400, 400);
}
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") )
label.setText( Integer.toString( list.getVisibleIndex() ) );
else
label1.setText( Integer.toString( list.getSelectedIndex() ) );
return true;
} // end if button
return super.action(evt, obj);
}
public static void main(String args[])
{
AppletFrame.startApplet("ListTest", "List Test");
}
}
/* Generic Applet to Application Frame
* @(#)AppletFrame.java 1.3 16 Nov 1995 17:26:57
* @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)
{
// 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
All platforms: awt.List.getVisibleIndex() always returns -1. It should return the
index of the last item in the list. (Docs say it is the last value set by
awt.List.makeVisible(), which it isn't doing either.)
Steps to reproduce
Compile and run the attached code
Press <makeVisible>
// note item Six in the list should now be visible
Press <getVisibleIndex>
// Note: the value next to this should be 5
/* tests the list stuff */
import java.awt.*;
import java.applet.Applet;
public class ListTest extends Applet
{
List list;
Label label;
Label label1;
public void init()
{
Panel panel = new Panel();
list = new List(4, false);
list.addItem("One");
list.addItem("Two");
list.addItem("Three");
list.addItem("Four");
list.addItem("Five");
list.addItem("Six");
panel.add( new Button("makeVisible") );
panel.add( new Button("getVisibleIndex") );
panel.add( label = new Label("Nothing") );
panel.add( new Button("getSelectedIndex") );
panel.add( label1 = new Label("Nothing") );
add(panel);
add(list);
resize(400, 400);
}
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") )
label.setText( Integer.toString( list.getVisibleIndex() ) );
else
label1.setText( Integer.toString( list.getSelectedIndex() ) );
return true;
} // end if button
return super.action(evt, obj);
}
public static void main(String args[])
{
AppletFrame.startApplet("ListTest", "List Test");
}
}
/* Generic Applet to Application Frame
* @(#)AppletFrame.java 1.3 16 Nov 1995 17:26:57
* @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)
{
// 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
- relates to
-
JDK-1230210 Solaris only: List.makeVisible() of the last item causes list to scroll too far
-
- Closed
-