当前位置: 首页>>代码示例>>Java>>正文


Java JList.setSelectedIndex方法代码示例

本文整理汇总了Java中javax.swing.JList.setSelectedIndex方法的典型用法代码示例。如果您正苦于以下问题:Java JList.setSelectedIndex方法的具体用法?Java JList.setSelectedIndex怎么用?Java JList.setSelectedIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JList的用法示例。


在下文中一共展示了JList.setSelectedIndex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRemoveOneSubModule

import javax.swing.JList; //导入方法依赖的package包/类
public void testRemoveOneSubModule() throws Exception {
    SuiteProject suite1 = generateSuite("suite1");
    NbModuleProject module1a = TestBase.generateSuiteComponent(suite1, "module1a");
    TestBase.generateSuiteComponent(suite1, "module1b");
    SuiteProperties suite1Props = getSuiteProperties(suite1);
    
    SuiteSubModulesListModel model = suite1Props.getModulesListModel();
    assertNotNull(model);
    
    // simulate removing first item from the list
    JList moduleList = new JList(model);
    moduleList.setSelectedIndex(0);
    model.removeModules(Arrays.asList(moduleList.getSelectedValues()));
    assertEquals("one subModule should left", 1, model.getSize());
    
    saveProperties(suite1Props);
    
    SubprojectProvider spp = getSubProjectProvider(suite1);
    assertEquals("one module should be left", 1, spp.getSubprojects().size());
    NbModuleProject project = (NbModuleProject) spp.getSubprojects().toArray()[0];
    assertEquals("module1b should be the one", "org.example.module1b", project.getCodeNameBase());
    assertSame("module1b module is still suite component module", NbModuleType.SUITE_COMPONENT, project.getModuleType());
    
    // assert that the remove module (module1a) is standalone
    assertSame("module1a module is standalone module now", NbModuleType.STANDALONE, module1a.getModuleType());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:SuitePropertiesTest.java

示例2: draw

import javax.swing.JList; //导入方法依赖的package包/类
/** Constructs rest of dialog.
*/
private void draw () {
    list = new JList(listModel);
    list.addListSelectionListener (new javax.swing.event.ListSelectionListener () {
                                       public void valueChanged (javax.swing.event.ListSelectionEvent evt) {
                                           updateSaveButton ();
                                       }
                                   }
                                  );
    // bugfix 37941, select first item in list
    if (!listModel.isEmpty ()) {
        list.setSelectedIndex (0);
    } else {                              
        updateSaveButton ();
    }
    JScrollPane scroll = new JScrollPane (list);
 setBorder(BorderFactory.createEmptyBorder( 12, 12, 11, 12));
    add(scroll, java.awt.BorderLayout.CENTER);
    list.setCellRenderer(new ExitDlgListCellRenderer());
    list.getAccessibleContext().setAccessibleName((NbBundle.getBundle(ExitDialog.class)).getString("ACSN_ListOfChangedFiles"));
    list.getAccessibleContext().setAccessibleDescription((NbBundle.getBundle(ExitDialog.class)).getString("ACSD_ListOfChangedFiles"));
    this.getAccessibleContext().setAccessibleDescription((NbBundle.getBundle(ExitDialog.class)).getString("ACSD_ExitDialog"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ExitDialog.java

示例3: matchSelection

import javax.swing.JList; //导入方法依赖的package包/类
private void matchSelection( DocumentEvent e ) {
    if( isIgnoreSelectionEvents( combo ) )
        return;
    try {
        setIgnoreSelectionEvents( combo, true );
        if( !combo.isDisplayable() )
            return;
        String editorText;
        try {
            editorText = e.getDocument().getText( 0, e.getDocument().getLength() );
        } catch( BadLocationException ex ) {
            //ignore
            return;
        }

        if( null != combo.getSelectedItem() && combo.getSelectedItem().toString().equals(editorText) )
            return;

        if( !combo.isPopupVisible() ) {
            combo.showPopup();
        }

        JList list = getPopupList( combo );
        if( null == list )
            return;

        int matchIndex = findMatch( combo, editorText );

        if( matchIndex >= 0 ) {
            list.setSelectedIndex( matchIndex );
            Rectangle rect = list.getCellBounds(matchIndex, matchIndex);
            if( null != rect )
                list.scrollRectToVisible( rect );
        } else {
            list.clearSelection();
            list.scrollRectToVisible( new Rectangle( 1, 1 ) );
        }
    } finally {
        setIgnoreSelectionEvents( combo, false );
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:ComboBoxAutoCompleteSupport.java

示例4: selectProcessToKill

import javax.swing.JList; //导入方法依赖的package包/类
static List<BuildExecutionSupport.Item> selectProcessToKill(List<BuildExecutionSupport.Item> toStop) {
    // Add all threads, sorted by display name.
    DefaultListModel model = new DefaultListModel();
    StopBuildingAlert alert = new StopBuildingAlert();
    final JList list = alert.buildsList;
    Comparator<BuildExecutionSupport.Item> comp = new Comparator<BuildExecutionSupport.Item>() {
        private final Collator coll = Collator.getInstance();
        @Override
        public int compare(BuildExecutionSupport.Item t1, BuildExecutionSupport.Item t2) {
            String n1 = t1.getDisplayName();
            String n2 = t2.getDisplayName();
            int r = coll.compare(n1, n2);
            if (r != 0) {
                return r;
            } else {
                // Arbitrary. XXX Note that there is no way to predict which is
                // which if you have more than one build running. Ideally it
                // would be subsorted by creation time, probably.
                return System.identityHashCode(t1) - System.identityHashCode(t2);
            }
        }
    };
    SortedSet<BuildExecutionSupport.Item> items = new TreeSet<BuildExecutionSupport.Item>(comp);
    items.addAll(toStop);

    for (BuildExecutionSupport.Item t : items) {
        model.addElement(t);
    }
    list.setModel(model);
    list.setSelectedIndex(0);
    // Make a dialog with buttons "Stop Building" and "Cancel".
    DialogDescriptor dd = new DialogDescriptor(alert, NbBundle.getMessage(StopBuildingAlert.class, "TITLE_SBA"));
    dd.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
    final JButton stopButton = new JButton(NbBundle.getMessage(StopBuildingAlert.class, "LBL_SBA_stop"));
    list.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            stopButton.setEnabled(list.getSelectedValue() != null);
        }
    });
    dd.setOptions(new Object[] {stopButton, DialogDescriptor.CANCEL_OPTION});
    DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
    List<BuildExecutionSupport.Item> toRet = new ArrayList<BuildExecutionSupport.Item>();
    if (dd.getValue() == stopButton) {
        Object[] selectedItems = list.getSelectedValues();
        for (Object o : selectedItems) {
            toRet.add((BuildExecutionSupport.Item)o);
        }
    }
    return toRet;

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:StopBuildingAlert.java

示例5: addNewType

import javax.swing.JList; //导入方法依赖的package包/类
private void addNewType(String t, JList list, String prefKey) {
    ((DefaultListModel)list.getModel()).addElement(t);
    list.setSelectedIndex(list.getModel().getSize() - 1);
    updatePreference(list, prefKey);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:UseSpecificCatchCustomizer.java

示例6: logFilesList

import javax.swing.JList; //导入方法依赖的package包/类
private JList<String> logFilesList() {
	
	
	file = new File(System.getProperty("user.dir") + File.separator + "Logging Store/");
	
	final JFileChooser fileChooser = new JFileChooser();
	fileChooser.setCurrentDirectory(file);
	fileChooser.setMultiSelectionEnabled(true);

	final DefaultListModel<String> model = new DefaultListModel<String>();
	
	final JList<String> list = new JList<String>(model);
	list.setPreferredSize(new Dimension(85, 480));
	list.setFont(new Font("Dialog", Font.PLAIN, 12));
	list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	list.setSelectedIndex(0);
	list.setFixedCellHeight(18);
	list.addMouseListener(new MouseAdapter() {
		@Override
		public void mousePressed(MouseEvent e) {
			if (e.getClickCount() == 2) {
				selectedItem = list.getSelectedValue();
				getSelectedFileName();
			}
		}
	});
	
	list.setCellRenderer(new LogRecordsListRenderer());

	File[] selectedFiles = fileChooser.getCurrentDirectory().listFiles();

	for (File f : selectedFiles) {
		if (f.getName().indexOf(".log") != -1) {
			model.addElement(f.getName());
		}else {
			continue;
		}
	}
	if(model.isEmpty()) {
		model.addElement("List is empty!");
	}
	
	return list;
}
 
开发者ID:Coder-ACJHP,项目名称:Hotel-Properties-Management-System,代码行数:45,代码来源:ReadLogsWindow.java


注:本文中的javax.swing.JList.setSelectedIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。