SingleModeDeselect.java revision 11017:beec47aecf5a
1248590Smm/*
2248590Smm * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3248590Smm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4248590Smm *
5248590Smm * This code is free software; you can redistribute it and/or modify it
6248590Smm * under the terms of the GNU General Public License version 2 only, as
7248590Smm * published by the Free Software Foundation.
8248590Smm *
9248590Smm * This code is distributed in the hope that it will be useful, but WITHOUT
10248590Smm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11248590Smm * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12248590Smm * version 2 for more details (a copy is included in the LICENSE file that
13248590Smm * accompanied this code).
14248590Smm *
15248590Smm * You should have received a copy of the GNU General Public License version
16248590Smm * 2 along with this work; if not, write to the Free Software Foundation,
17248590Smm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18248590Smm *
19248590Smm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20248590Smm * or visit www.oracle.com if you need additional information or have any
21248590Smm * questions.
22248590Smm */
23248590Smm
24248590Smm/*
25248590Smm  @test
26248590Smm  @bug 6248040
27248590Smm  @summary List.deselect() de-selects the currently selected item regardless of the index, win32
28248590Smm  @author Dmitry Cherepanov area=awt.list
29248590Smm  @run main SingleModeDeselect
30248590Smm*/
31248590Smm
32248590Smmimport java.awt.*;
33248590Smm
34248590Smmpublic class SingleModeDeselect
35248590Smm{
36248590Smm    public static final void main(String args[])
37248590Smm    {
38248590Smm        final Frame frame = new Frame();
39248590Smm        final List list = new List();
40248590Smm
41248590Smm        list.add(" item 0 ");
42248590Smm        list.add(" item 1 ");
43248590Smm
44248590Smm        frame.add(list);
45318483Smm        frame.setLayout(new FlowLayout());
46248590Smm        frame.setBounds(100,100,300,300);
47248590Smm        frame.setVisible(true);
48248590Smm
49248590Smm        list.select(0);
50248590Smm        list.deselect(1);
51248590Smm
52248590Smm        try {
53248590Smm            Robot robot = new Robot();
54248590Smm            robot.waitForIdle();
55318483Smm        }catch(Exception ex) {
56248590Smm            ex.printStackTrace();
57            throw new RuntimeException("Unexpected failure");
58        }
59
60        if (list.getSelectedIndex() != 0){
61            throw new RuntimeException("Test failed: List.getSelectedIndex() returns "+list.getSelectedIndex());
62        }
63
64    }//End  init()
65}
66