javax.swing.JList#setSelectedIndex ( )源码实例Demo

下面列出了javax.swing.JList#setSelectedIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: egdownloader   文件: GroupWindow.java
public GroupWindow(List<File> groups, final EgDownloaderWindow mainWindow){
	super(Version.NAME + "任务组列表");
	this.mainWindow = mainWindow;
	this.setSize(300, 400);
	this.setResizable(false);
	this.setIconImage(IconManager.getIcon("group").getImage());
	this.setLocationRelativeTo(null);
	this.getContentPane().setLayout(null);
	this.setDefaultCloseOperation(mainWindow == null ? EXIT_ON_CLOSE : DISPOSE_ON_CLOSE);
	JLabel tipLabel = new AJLabel("双击选择任务组", new Color(67,44,1), 15, 15, 100, 30);
	JButton addGroupBtn = new AJButton("新建", IconManager.getIcon("add"), new OperaBtnMouseListener(this, MouseAction.CLICK, new IListenerTask() {
						public void doWork(Window window, MouseEvent e) {
							new AddGroupDialog((GroupWindow) window, mainWindow);
						}
					}) , 215, 15, 62, 30);
	addGroupBtn.setUI(AJButton.blueBtnUi);
	JList list = new GroupList(groups, this, mainWindow);
	list.setSelectedIndex(0);
	JScrollPane listPane = new JScrollPane(list);
	listPane.setBounds(new Rectangle(10, 50, 270, 300));
	listPane.setAutoscrolls(true);
	listPane.getViewport().setBackground(new Color(254,254,254));
	ComponentUtil.addComponents(this.getContentPane(), tipLabel, addGroupBtn, listPane);
	
	this.setVisible(true);
}
 
源代码2 项目: dualsub   文件: Validator.java
public static void goUp(JList<File> list) {
	int[] selected = isSelected(list);
	if (selected.length > 1) {
		Alert.error(I18N.getHtmlText("Validator.onlyOne.alert"));
		return;
	} else if (selected.length == 1 && selected[0] > 0) {
		File removed = ((DefaultListModel<File>) list.getModel())
				.remove(selected[0]);
		File before = ((DefaultListModel<File>) list.getModel())
				.remove(selected[0] - 1);
		((DefaultListModel<File>) list.getModel()).add(selected[0] - 1,
				removed);
		((DefaultListModel<File>) list.getModel()).add(selected[0], before);
		list.setSelectedIndex(selected[0] - 1);
	}
}
 
源代码3 项目: jsyn   文件: InstrumentBrowser.java
public InstrumentBrowser(InstrumentLibrary library) {
    this.library = library;
    JPanel horizontalPanel = new JPanel();
    horizontalPanel.setLayout(new GridLayout(1, 2));

    final JList<VoiceDescription> instrumentList = new JList<VoiceDescription>(library.getVoiceDescriptions());
    setupList(instrumentList);
    instrumentList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() == false) {
                int n = instrumentList.getSelectedIndex();
                if (n >= 0) {
                    showPresetList(n);
                }
            }
        }
    });

    JScrollPane listScroller1 = new JScrollPane(instrumentList);
    listScroller1.setPreferredSize(new Dimension(250, 120));
    add(listScroller1);

    instrumentList.setSelectedIndex(0);
}
 
源代码4 项目: jsyn   文件: InstrumentBrowser.java
public InstrumentBrowser(InstrumentLibrary library) {
    this.library = library;
    JPanel horizontalPanel = new JPanel();
    horizontalPanel.setLayout(new GridLayout(1, 2));

    final JList<VoiceDescription> instrumentList = new JList<VoiceDescription>(library.getVoiceDescriptions());
    setupList(instrumentList);
    instrumentList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() == false) {
                int n = instrumentList.getSelectedIndex();
                if (n >= 0) {
                    showPresetList(n);
                }
            }
        }
    });

    JScrollPane listScroller1 = new JScrollPane(instrumentList);
    listScroller1.setPreferredSize(new Dimension(250, 120));
    add(listScroller1);

    instrumentList.setSelectedIndex(0);
}
 
源代码5 项目: iBioSim   文件: FBAObjective.java
private static void removeObjective(JList objectiveList) {
	// find where the selected objective is on the list
	int index = objectiveList.getSelectedIndex();
	if (index != -1) {
		objectiveList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
		// remove it
		Utility.remove(objectiveList);
		objectiveList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		if (index < objectiveList.getModel().getSize()) {
			objectiveList.setSelectedIndex(index);
		}
		else {
			objectiveList.setSelectedIndex(index - 1);
		}
	}
}
 
源代码6 项目: iBioSim   文件: Events.java
/**
 * Remove an event from a list and SBML gcm.getSBMLDocument()
 * 
 * @param events
 *            a list of events
 * @param gcm.getSBMLDocument()
 *            an SBML gcm.getSBMLDocument() from which to remove the event
 * @param usedIDs
 *            a list of all IDs current in use
 * @param ev
 *            an array of all events
 */
private void removeEvent(JList events, BioModel gcm) {
	int index = events.getSelectedIndex();
	if (index != -1) {
		String selected = ((String) events.getSelectedValue()).split("\\[")[0];
		removeTheEvent(gcm, selected);
		events.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
		Utility.remove(events);
		events.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		if (index < events.getModel().getSize()) {
			events.setSelectedIndex(index);
		}
		else {
			events.setSelectedIndex(index - 1);
		}
		modelEditor.setDirty(true);
		modelEditor.makeUndoPoint();
	}
}
 
源代码7 项目: dualsub   文件: Validator.java
public static void goDown(JList<File> list) {
	int[] selected = isSelected(list);
	if (selected.length > 1) {
		Alert.error(I18N.getHtmlText("Validator.onlyOne.alert"));
		return;
	} else if (selected.length == 1
			&& selected[0] < list.getModel().getSize() - 1) {
		File after = ((DefaultListModel<File>) list.getModel())
				.remove(selected[0] + 1);
		File removed = ((DefaultListModel<File>) list.getModel())
				.remove(selected[0]);
		((DefaultListModel<File>) list.getModel()).add(selected[0], after);
		((DefaultListModel<File>) list.getModel()).add(selected[0] + 1,
				removed);
		list.setSelectedIndex(selected[0] + 1);
	}
}
 
源代码8 项目: intellij   文件: AddSourceToProjectDialog.java
AddSourceToProjectDialog(Project project, List<TargetInfo> targets) {
  super(project, /* canBeParent= */ true, IdeModalityType.MODELESS);
  this.project = project;

  mainPanel = new JPanel(new VerticalLayout(12));

  JList<TargetInfo> targetsComponent = new JBList<>(targets);
  if (targets.size() == 1) {
    targetsComponent.setSelectedIndex(0);
  }
  this.targetsComponent = targetsComponent;

  setTitle("Add Source File to Project");
  setupUi();
  init();
}
 
源代码9 项目: zap-extensions   文件: WebSocketUiHelper.java
public void setSelectedOpcodes(List<String> opcodes) {
    JList<String> opcodesList = getOpcodeList();
    if (opcodes == null || opcodes.contains(SELECT_ALL_OPCODES)) {
        opcodesList.setSelectedIndex(0);
    } else {
        int j = 0;
        int[] selectedIndices = new int[opcodes.size()];
        ListModel<String> model = opcodesList.getModel();
        for (int i = 0; i < model.getSize(); i++) {
            String item = model.getElementAt(i);
            if (opcodes.contains(item)) {
                selectedIndices[j++] = i;
            }
        }
        opcodesList.setSelectedIndices(selectedIndices);
    }
}
 
源代码10 项目: zap-extensions   文件: WebSocketUiHelper.java
public void setSelectedChannelIds(List<Integer> channelIds) {
    JList<WebSocketChannelDTO> channelsList = getChannelsList();
    if (channelIds == null || channelIds.contains(-1)) {
        channelsList.setSelectedIndex(0);
    } else {
        int[] selectedIndices = new int[channelIds.size()];
        ListModel<WebSocketChannelDTO> model = channelsList.getModel();
        for (int i = 0, j = 0; i < model.getSize(); i++) {
            WebSocketChannelDTO channel = model.getElementAt(i);
            if (channelIds.contains(channel.id)) {
                selectedIndices[j++] = i;
            }
        }
        channelsList.setSelectedIndices(selectedIndices);
    }
}
 
源代码11 项目: WorldGrower   文件: StatusMessageDialog.java
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());
}
 
源代码12 项目: JAVA-MVC-Swing-Monopoly   文件: FrameConfig.java
/**
 * 
 * ��ͼѡ�����
 * 
 */
private JPanel createMapSelectPanel() {
	JPanel jp = new JPanel();
	jp.setLayout(new GridLayout());
	jp.setBackground(new Color(235,236,237));
	JPanel lPane = new JPanel(new BorderLayout());
	String[] maps = { "\"LOVE��ͼ\"", "\"���ݵ�ͼ\"", "\"���˵�ͼ\"" };
	final ImageIcon[] maps1 = {
			new ImageIcon("images/other/1.png"),
			new ImageIcon("images/other/2.png"),
			new ImageIcon("images/other/3.png") };
	final JList jlst = new JList(maps);
	jlst.setSelectedIndex(0);
	final JLabel mapV = new JLabel(maps1[0]);
	final JButton ok = new JButton("ȷ��");
	ok.addActionListener(new ActionListener() {

		@Override
		public void actionPerformed(ActionEvent arg0) {
			GameRunning.MAP = jlst.getSelectedIndex() + 1;
			ok.setText("��ѡ");
		}
	});
	jlst.addListSelectionListener(new ListSelectionListener() {
		@Override
		public void valueChanged(ListSelectionEvent e) {
			mapV.setIcon(maps1[jlst.getSelectedIndex()]);
			ok.setText("ȷ��");
		}
	});
	lPane.add(jlst);
	lPane.add(ok, BorderLayout.SOUTH);
	JPanel rPane = new JPanel();
	rPane.add(mapV);
	JSplitPane jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
			false, lPane, rPane);
	jp.add(jSplitPane);
	return jp;
}
 
源代码13 项目: magarena   文件: ImageSetsPanel.java
ImageSetsPanel(final AvatarImagesScreen screen) {

        // List of avatar image sets.
        final JList<AvatarImageSet> imageSetsList = new JList<>(getAvatarImageSetsArray());
        imageSetsList.setOpaque(false);
        imageSetsList.addListSelectionListener(e -> {
            if (!e.getValueIsAdjusting()) {
                SwingUtilities.invokeLater(() -> {
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    screen.displayImageSetIcons(imageSetsList.getSelectedValue());
                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                });
            }
        });
        imageSetsList.setSelectedIndex(0);

        final AvatarListCellRenderer renderer = new AvatarListCellRenderer();
        imageSetsList.setCellRenderer(renderer);

        final JScrollPane scrollPane = new JScrollPane();
        scrollPane.setViewportView(imageSetsList);
        scrollPane.setBorder(BorderFactory.createEmptyBorder());
        scrollPane.setOpaque(false);
        scrollPane.getViewport().setOpaque(false);

        setLayout(new MigLayout("insets 0, gap 0, flowy"));
        setBorder(FontsAndBorders.BLACK_BORDER);
        add(scrollPane, "w 100%, h 100%");

        refreshStyle();
    }
 
源代码14 项目: triplea   文件: DownloadMapsWindow.java
private static JList<String> newGameSelectionList(
    final DownloadFileDescription selectedMap,
    final List<DownloadFileDescription> maps,
    final JEditorPane descriptionPanel,
    final DefaultListModel<String> model) {
  final JList<String> gamesList = new JList<>(model);
  final int selectedIndex = maps.indexOf(selectedMap);
  gamesList.setSelectedIndex(selectedIndex);

  final String text = maps.get(selectedIndex).toHtmlString();
  descriptionPanel.setText(text);
  descriptionPanel.scrollRectToVisible(new Rectangle(0, 0, 0, 0));
  return gamesList;
}
 
源代码15 项目: triplea   文件: TripleAFrame.java
/**
 * Prompts the user to select the territory on which they wish to conduct a rocket attack.
 *
 * @param candidates The collection of territories on which the user may conduct a rocket attack.
 * @param from The territory from which the rocket attack is conducted.
 * @return The selected territory or {@code null} if no territory was selected.
 */
public Territory getRocketAttack(final Collection<Territory> candidates, final Territory from) {
  messageAndDialogThreadPool.waitForAll();
  mapPanel.centerOn(from);

  final Supplier<Territory> action =
      () -> {
        final JList<Territory> list = new JList<>(SwingComponents.newListModel(candidates));
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list.setSelectedIndex(0);
        final JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        final JScrollPane scroll = new JScrollPane(list);
        panel.add(scroll, BorderLayout.CENTER);
        if (from != null) {
          panel.add(BorderLayout.NORTH, new JLabel("Targets for rocket in " + from.getName()));
        }
        final String[] options = {"OK", "Dont attack"};
        final String message = "Select Rocket Target";
        final int selection =
            JOptionPane.showOptionDialog(
                TripleAFrame.this,
                panel,
                message,
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE,
                null,
                options,
                null);
        return (selection == 0) ? list.getSelectedValue() : null;
      };
  return Interruptibles.awaitResult(() -> SwingAction.invokeAndWaitResult(action))
      .result
      .orElse(null);
}
 
源代码16 项目: netbeans   文件: UseSpecificCatchCustomizer.java
private void addNewType(String t, JList list, String prefKey) {
    ((DefaultListModel)list.getModel()).addElement(t);
    list.setSelectedIndex(list.getModel().getSize() - 1);
    updatePreference(list, prefKey);
}
 
源代码17 项目: netbeans   文件: ComboBoxAutoCompleteSupport.java
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 );
    }
}
 
源代码18 项目: iBioSim   文件: Constraints.java
public Constraints(BioModel bioModel, ModelEditor modelEditor) {
	super(new BorderLayout());
	this.bioModel = bioModel;
	this.modelEditor = modelEditor;
	Model model = bioModel.getSBMLDocument().getModel();
	addConstraint = new JButton("Add Constraint");
	removeConstraint = new JButton("Remove Constraint");
	editConstraint = new JButton("Edit Constraint");
	constraints = new JList();
	ListOf<Constraint> listOfConstraints = model.getListOfConstraints();
	String[] cons = new String[model.getConstraintCount()];
	for (int i = 0; i < model.getConstraintCount(); i++) {
		Constraint constraint = listOfConstraints.get(i);
		if (!constraint.isSetMetaId()) {
			String constraintId = "c0";
			int cn = 0;
			while (bioModel.isSIdInUse(constraintId)) {
				cn++;
				constraintId = "c" + cn;
			}
			SBMLutilities.setMetaId(constraint, constraintId);
		}
		cons[i] = constraint.getMetaId();
		cons[i] += SBMLutilities.getDimensionString(constraint);
	}
	JPanel addRem = new JPanel();
	addRem.add(addConstraint);
	addRem.add(removeConstraint);
	addRem.add(editConstraint);
	addConstraint.addActionListener(this);
	removeConstraint.addActionListener(this);
	editConstraint.addActionListener(this);
	JLabel panelLabel = new JLabel("List of Constraints:");
	JScrollPane scroll = new JScrollPane();
	scroll.setMinimumSize(new Dimension(260, 220));
	scroll.setPreferredSize(new Dimension(276, 152));
	scroll.setViewportView(constraints);
	edu.utah.ece.async.ibiosim.dataModels.biomodel.util.Utility.sort(cons);
	constraints.setListData(cons);
	constraints.setSelectedIndex(0);
	constraints.addMouseListener(this);
	this.add(panelLabel, "North");
	this.add(scroll, "Center");
	this.add(addRem, "South");
}
 
源代码19 项目: AMIDST   文件: LicenseWindow.java
public LicenseWindow() {
	super("Licenses");
	setIconImage(Amidst.icon);
	licenseText.setEditable(false);
	licenseText.setLineWrap(true);
	licenseText.setWrapStyleWord(true);
	
	licenses.add(new License("AMIDST",		     "licenses/amidst.txt"));
	licenses.add(new License("Args4j",		     "licenses/args4j.txt"));
	licenses.add(new License("Gson",			 "licenses/gson.txt"));
	licenses.add(new License("JGoogleAnalytics", "licenses/jgoogleanalytics.txt"));
	licenses.add(new License("JNBT",			 "licenses/jnbt.txt"));
	licenses.add(new License("Kryonet",          "licenses/kryonet.txt"));
	licenses.add(new License("MiG Layout",	     "licenses/miglayout.txt"));
	licenses.add(new License("Rhino",			 "licenses/rhino.txt"));
	licenseList = new JList(licenses.toArray());
	licenseList.setBorder(new LineBorder(Color.darkGray, 1));
	Container contentPane = this.getContentPane();
	MigLayout layout = new MigLayout();
	contentPane.setLayout(layout);
	contentPane.add(licenseList, "w 100!, h 0:2400:2400");
	JScrollPane scrollPane = new JScrollPane(licenseText);
	scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	contentPane.add(scrollPane, "w 0:4800:4800, h 0:2400:2400");
	setSize(870, 550);
	setVisible(true);
	licenseList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	licenseList.addListSelectionListener(new ListSelectionListener() {
		@Override
		public void valueChanged(ListSelectionEvent e) {
			License license = (License)licenseList.getSelectedValue();
			license.load();
			
			if (license.isLoaded()) {
				licenseText.setText(license.getContents());
				licenseText.setCaretPosition(0);
			}
		}
	});
	licenseList.setSelectedIndex(0);
}
 
源代码20 项目: Astrosoft   文件: YogaCombinationsView.java
public YogaCombinationsView(String title, YogaResults yogaResults, PlanetaryInfo planetaryInfo) {
	
	super(viewSize, viewLoc);
	this.planetaryInfo = planetaryInfo;
	this.yogaResults = yogaResults;
	
	JPanel yogaPanel = new JPanel();
	
	yogaList = new JList(yogaResults.getYogas().toArray());
	yogaList.setFont(UIUtil.getFont("Tahoma", Font.PLAIN, 11));
	
	yogaList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	yogaList.setSelectedIndex(0);
	
	yogaPanel.add(yogaList);
	
	yogaPanel.setPreferredSize(yogaSize);	
	
	
	final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, yogaPanel, createResultPane());
	
	yogaPanel.setBorder(BorderFactory.createEtchedBorder());
	splitPane.setBorder(BorderFactory.createEmptyBorder());
	
	yogaList.addListSelectionListener(new ListSelectionListener(){

		public void valueChanged(ListSelectionEvent e) {
			//splitPane.remove(chartPanel);
			yogaChanged((YogaResults.Result)yogaList.getSelectedValue());
			//splitPane.add(chartPanel);
		}
	});
	
	add(splitPane,BorderLayout.CENTER);
}