|
Java example source code file (bug6823603.java)
The bug6823603.java Java example source code
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
@bug 6823603
@summary Generics: JList
@author Florian Brunner
@run main bug6823603
*/
import java.util.Arrays;
import java.util.List;
import java.util.Vector;
import java.util.Enumeration;
import java.awt.*;
import javax.swing.*;
public class bug6823603 {
private static final String TEST_ELEMENT = "Test1";
/**
* @param args the command line arguments
*/
@SuppressWarnings("unchecked")
public static void main(String[] args) {
testRawSignatures();
testGenericSignatures();
testGetSelectedValuesList(); // new method
}
@SuppressWarnings("unchecked")
private static void testRawSignatures() {
// Test JList
ListModel rawTestModel = new DefaultListModel();
new JList();
new JList(rawTestModel);
new JList(new Object[]{TEST_ELEMENT});
JList rawTestList = new JList(new Vector());
rawTestList.getPrototypeCellValue();
rawTestList.setPrototypeCellValue(TEST_ELEMENT);
rawTestList.getCellRenderer();
rawTestList.setCellRenderer(new DefaultListCellRenderer());
rawTestList.getModel();
rawTestList.setModel(rawTestModel);
rawTestList.setListData(new Object[]{TEST_ELEMENT});
rawTestList.setListData(new Vector());
@SuppressWarnings("deprecation")
Object[] selectedValues = rawTestList.getSelectedValues();
rawTestList.getSelectedValue();
// Test ListCellRenderer
ListCellRenderer rawTestCellRenderer = new DefaultListCellRenderer();
String testEntry = "Test";
@SuppressWarnings("unchecked")
JList rawJList = new JList(new Object[]{testEntry});
rawTestCellRenderer.getListCellRendererComponent(rawJList,
testEntry, 0, true, true);
// Test ListModel
DefaultListModel testModel = new DefaultListModel();
testModel.addElement(TEST_ELEMENT);
rawTestModel = testModel;
rawTestModel.getElementAt(0);
// Test DefaultListModel
DefaultListModel defaultListModel = new DefaultListModel();
defaultListModel.addElement(TEST_ELEMENT);
defaultListModel.getElementAt(0);
defaultListModel.elements();
defaultListModel.elementAt(0);
defaultListModel.firstElement();
defaultListModel.lastElement();
String testElement2 = "Test2";
defaultListModel.setElementAt(testElement2, 0);
defaultListModel.insertElementAt(TEST_ELEMENT, 0);
defaultListModel.get(0);
defaultListModel.set(0, testElement2);
defaultListModel.add(0, TEST_ELEMENT);
defaultListModel.remove(0);
// Test AbstractListModel
@SuppressWarnings("serial")
ListModel abstractListModel = new AbstractListModel() {
public int getSize() {
throw new UnsupportedOperationException("Not supported yet.");
}
public Object getElementAt(int index) {
throw new UnsupportedOperationException("Not supported yet.");
}
};
// Test DefaultListCellRenderer
DefaultListCellRenderer cellRenderer = new DefaultListCellRenderer();
@SuppressWarnings("unchecked")
JList list = new JList(new Object[]{testEntry});
cellRenderer.getListCellRendererComponent(rawJList, testEntry, 0, true, true);
}
private static <E> void testGenericSignatures() {
// Test JList
ListModel<String> stringListModel = new DefaultListModel
Other Java examples (source code examples)Here is a short list of links related to this Java bug6823603.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.