jdk/test/javax/swing/JTable/7027139/bug7027139.java
changeset 12173 80420757767c
equal deleted inserted replaced
12035:b2c4bc120719 12173:80420757767c
       
     1 /*
       
     2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /* @test
       
    25    @bug 7027139
       
    26    @summary getFirstIndex() does not return the first index that has changed
       
    27    @author Pavel Porvatov
       
    28 */
       
    29 
       
    30 import javax.swing.*;
       
    31 import javax.swing.event.ListSelectionEvent;
       
    32 import javax.swing.event.ListSelectionListener;
       
    33 
       
    34 public class bug7027139 {
       
    35     public static void main(String[] args) throws Exception {
       
    36         SwingUtilities.invokeAndWait(new Runnable() {
       
    37             public void run() {
       
    38                 JTable orderTable = new JTable(new String[][]{
       
    39                         {"Item 1 1", "Item 1 2"},
       
    40                         {"Item 2 1", "Item 2 2"},
       
    41                         {"Item 3 1", "Item 3 2"},
       
    42                         {"Item 4 1", "Item 4 2"},
       
    43                 },
       
    44                         new String[]{"Col 1", "Col 2"});
       
    45 
       
    46                 ListSelectionModel selectionModel = orderTable.getSelectionModel();
       
    47                 selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
       
    48                 selectionModel.addListSelectionListener(new ListSelectionListener() {
       
    49                     public void valueChanged(ListSelectionEvent e) {
       
    50                         if (e.getValueIsAdjusting()) {
       
    51                             return;
       
    52                         }
       
    53 
       
    54                         if (e.getFirstIndex() < 0) {
       
    55                             throw new RuntimeException("Test bug7027139 failed");
       
    56                         }
       
    57                     }
       
    58                 });
       
    59 
       
    60                 orderTable.selectAll();
       
    61             }
       
    62         });
       
    63 
       
    64         System.out.println("Test bug7027139 passed");
       
    65     }
       
    66 }