Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2003-2008, Open Source Geospatial Foundation (OSGeo)
 *        
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

import javax.swing.JList;

public class Main {
    public static void setSelection(JList list, Object element) {
        for (int i = 0; i < list.getModel().getSize(); i++) {
            Object value = (Object) list.getModel().getElementAt(i);
            if (value == element) {
                list.setSelectedIndex(i);
                list.scrollRectToVisible(list.getCellBounds(i, i));
                return;
            }
        }
    }
}