Java Code Examples for javax.swing.JList#ensureIndexIsVisible()

The following examples show how to use javax.swing.JList#ensureIndexIsVisible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditCustomCategoryDialog.java    From tda with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void moveFilter(JList fromList, JList toList, int selectedItem) {
    Filter filter = (Filter) ((DefaultListModel) fromList.getModel()).getElementAt(selectedItem);
    ((DefaultListModel) fromList.getModel()).removeElementAt(selectedItem);
    
    DefaultListModel dlm = ((DefaultListModel) toList.getModel());

    dlm.ensureCapacity(dlm.getSize() + 1);
    dlm.addElement(filter);
    toList.ensureIndexIsVisible(dlm.getSize());
}
 
Example 2
Source File: StatusMessageDialog.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
public StatusMessageDialog(List<StatusMessage> statusMessages, ImageInfoReader imageInfoReader, SoundIdReader soundIdReader, JFrame parentFrame) {
	super(700, 475, imageInfoReader);
	
	JScrollPane scrollPane = JScrollPaneFactory.createScrollPane();
	scrollPane.setBounds(16, 16, 665, 380);
	addComponent(scrollPane);
	
	JList<StatusMessage> list = JListFactory.createJList(statusMessages.toArray(new StatusMessage[0]));
	list.setSelectedIndex(statusMessages.size() - 1);
	list.setCellRenderer(new StatusMessageListRenderer());
	scrollPane.setViewportView(list);
	list.ensureIndexIsVisible(list.getSelectedIndex());
	
	JPanel buttonPane = new JPanel();
	buttonPane.setLayout(new BorderLayout());
	buttonPane.setOpaque(false);
	buttonPane.setBounds(16, 417, 665, 40);
	addComponent(buttonPane);

	JButton okButton = JButtonFactory.createButton(" OK ", imageInfoReader, soundIdReader);
	okButton.setActionCommand("OK");
	buttonPane.add(okButton, BorderLayout.EAST);
	getRootPane().setDefaultButton(okButton);

	addActions(list, okButton);
	DialogUtils.createDialogBackPanel(this, parentFrame.getContentPane());
}
 
Example 3
Source File: NamedStoredProcedureQueryPanel.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void setResultClassSelectedValues(JList list, Object... values) {
    list.clearSelection();
    for (Object value : values) {
        int index = getElementIndexInList(list.getModel(), value);
        if (index >= 0) {
            list.addSelectionInterval(index, index);
        } else if (value instanceof String) {  //if external lib class not exists then add
            addAndSelectItemInList(list, value);
        }
    }
    list.ensureIndexIsVisible(list.getSelectedIndex());
}