List of usage examples for javax.swing DefaultListModel ensureCapacity
public void ensureCapacity(int minCapacity)
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(1000); for (int i = 0; i < 100; i++) { for (int j = 0; j < 5; j++) { model.addElement(labels[j]); }// w w w . j a v a2s. c om } Object[] objs = new Object[10]; System.out.println(model.elementAt(1)); JList jlist2 = new JList(model); jlist2.setVisibleRowCount(4); jlist2.setFixedCellHeight(12); jlist2.setFixedCellWidth(200); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); frame.setSize(300, 350); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(1000); for (int i = 0; i < 100; i++) { for (int j = 0; j < 5; j++) { model.addElement(labels[j]); }/*from w w w .java2 s . c o m*/ } Object[] objs = new Object[10]; model.copyInto(objs); JList jlist2 = new JList(model); jlist2.setVisibleRowCount(4); jlist2.setFixedCellHeight(12); jlist2.setFixedCellWidth(200); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); frame.setSize(300, 350); frame.setVisible(true); }
From source file:SizingSamples.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist1 = new JList(labels); jlist1.setVisibleRowCount(4);//from w ww. ja va2s . c o m DefaultListModel model = new DefaultListModel(); model.ensureCapacity(100); for (int i = 0; i < 100; i++) { model.addElement(Integer.toString(i)); } JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); JList jlist2 = new JList(model); jlist2.setVisibleRowCount(4); jlist2.setFixedCellHeight(12); jlist2.setFixedCellWidth(200); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); JList jlist3 = new JList(labels); jlist3.setVisibleRowCount(4); frame.add(jlist3, BorderLayout.SOUTH); frame.setSize(300, 350); frame.setVisible(true); }
From source file:SizingSamples.java
public static void main(String args[]) { JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(100); for (int i = 0; i < 100; i++) { model.addElement(Integer.toString(i)); }//from w w w. j ava2 s . com JList jlist2 = new JList(model); ListCellRenderer renderer = new FocusedTitleListCellRenderer(); jlist2.setCellRenderer(renderer); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); frame.setSize(300, 350); frame.setVisible(true); jlist2.ensureIndexIsVisible(50); }
From source file:SizingSamples.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JList jlist1 = new JList(labels); jlist1.setVisibleRowCount(4);/*from w w w .j a va 2 s . c o m*/ DefaultListModel model = new DefaultListModel(); model.ensureCapacity(1000); for (int i = 0; i < 100; i++) { for (int j = 0; j < 10; j++) { model.addElement(labels[j]); } } JScrollPane scrollPane1 = new JScrollPane(jlist1); contentPane.add(scrollPane1, BorderLayout.NORTH); JList jlist2 = new JList(model); jlist2.setVisibleRowCount(4); jlist2.setFixedCellHeight(12); jlist2.setFixedCellWidth(200); JScrollPane scrollPane2 = new JScrollPane(jlist2); contentPane.add(scrollPane2, BorderLayout.CENTER); JList jlist3 = new JList(labels); jlist3.setVisibleRowCount(4); contentPane.add(jlist3, BorderLayout.SOUTH); frame.setSize(300, 350); frame.setVisible(true); }
From source file:org.shaman.rpg.editor.dialog.DialogVisualElement.java
private void setupVisuals() { isInsideSetupVisuals = true;/* w w w .j a va2 s . co m*/ LOG.info("setup visuals"); contentPanel.removeAll(); commandPanels.clear(); //load dialog dialog = obj.load(); if (dialog == null) { contentPanel.add(new JLabel("unable to load the dialog")); isInsideSetupVisuals = false; return; } EditableProperties editableProperties = null; try { editableProperties = obj.getResourceBundle(); } catch (IOException ex) { LOG.log(Level.WARNING, "unable to load properties file", ex); } //set header nameTextField.getDocument().removeUndoableEditListener(undoRedo); nameTextField.setText(dialog.getName()); nameTextField.getDocument().addUndoableEditListener(undoRedo); String[] persons = dialog.getPersonList(); @SuppressWarnings("unchecked") DefaultListModel<String> listModel = (DefaultListModel<String>) personsList.getModel(); listModel.clear(); listModel.ensureCapacity(persons.length); for (String p : persons) { listModel.addElement(p); } personsList.clearSelection(); //set commands for (Command c : dialog.getCommands()) { CommandPanel p = null; if (c instanceof TextType) { p = new TextTypePanel(); } else if (c instanceof StopType) { p = new StopTypePanel(); } else if (c instanceof SetvarType) { p = new SetVarTypePanel(); } else if (c instanceof AddvarType) { p = new AddVarTypePanel(); } else if (c instanceof IfType) { p = new IfTypePanel(); } else if (c instanceof LabelType) { p = new LabelTypePanel(); } else if (c instanceof GotoType) { p = new GotoTypePanel(); } else if (c instanceof QuestionType) { p = new QuestionTypePanel(); } else { LOG.info("unknown command: " + c); continue; } p.setVisualElement(this); p.setDialog(dialog); p.setCommand(c); if (editableProperties != null) { p.updateResourceBundle(editableProperties, false); } p.setUndoRedo(undoRedo); contentPanel.add(p); commandPanels.add(p); } repaint(); recursiveValidate(contentPanel); repaint(); recursiveValidate(contentPanel); EventQueue.invokeLater(new Runnable() { @Override public void run() { recursiveValidate(contentPanel); contentPanel.repaint(); } }); isInsideSetupVisuals = false; }
From source file:org.shaman.rpg.editor.dialog.DialogVisualElement.java
private void updatePersons() { if (isInsideSetupVisuals) { return;/*from ww w . ja va 2 s. c o m*/ } //Extract persons @SuppressWarnings("unchecked") final DefaultListModel<String> listModel = (DefaultListModel<String>) personsList.getModel(); final String[] newPersons = new String[listModel.size()]; listModel.copyInto(newPersons); LOG.info("settings persons to " + Arrays.toString(newPersons)); final String[] oldPersons = dialog.getPersonList(); //send to dialog dialog.setPersonList(newPersons); updateDialogPersons(); // undo/redo undoRedo.undoableEditHappened(new UndoableEditEvent(dialog, new AbstractUndoableEdit() { @Override public void undo() throws CannotUndoException { super.undo(); isInsideSetupVisuals = true; listModel.clear(); listModel.ensureCapacity(oldPersons.length); for (String s : oldPersons) { listModel.addElement(s); } LOG.info("settings persons to " + Arrays.toString(oldPersons)); dialog.setPersonList(oldPersons); updateDialogPersons(); isInsideSetupVisuals = false; } @Override public void redo() throws CannotRedoException { super.redo(); isInsideSetupVisuals = true; listModel.clear(); listModel.ensureCapacity(newPersons.length); for (String s : newPersons) { listModel.addElement(s); } LOG.info("settings persons to " + Arrays.toString(newPersons)); dialog.setPersonList(newPersons); updateDialogPersons(); isInsideSetupVisuals = false; } })); }