Example usage for java.util Vector elementAt

List of usage examples for java.util Vector elementAt

Introduction

In this page you can find the example usage for java.util Vector elementAt.

Prototype

public synchronized E elementAt(int index) 

Source Link

Document

Returns the component at the specified index.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    model.addColumn("Col1");
    model.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    Vector data = model.getDataVector();
    Vector row = (Vector) data.elementAt(1);
    // Overwrite the first row with the copy
    Vector firstRow = (Vector) data.elementAt(0);
    for (int i = 0; i < row.size(); i++) {
        firstRow.set(i, row.get(i));// w w w.j  a  v  a 2s . c  o  m
    }

    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    model.addColumn("Col1");
    model.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    Vector data = model.getDataVector();
    Vector row = (Vector) data.elementAt(1);
    // Copy the first column
    int mColIndex = 0;
    List colData = new ArrayList(table.getRowCount());
    for (int i = 0; i < table.getRowCount(); i++) {
        row = (Vector) data.elementAt(i);
        colData.add(row.get(mColIndex));
    }/*from  www .  jav a 2  s.c  o  m*/
    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    model.addColumn("Col1");
    model.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    Vector data = model.getDataVector();
    Vector row = (Vector) data.elementAt(1);

    int mColIndex = 0;
    List colData = new ArrayList(table.getRowCount());
    for (int i = 0; i < table.getRowCount(); i++) {
        row = (Vector) data.elementAt(i);
        colData.add(row.get(mColIndex));
    }//from  w  w w. j  a  va  2  s . c  o  m

    // Append a new column with copied data
    model.addColumn("Col3", colData.toArray());

    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    model.addColumn("Col1");
    model.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    // Get all the table data
    Vector data = model.getDataVector();
    // Copy the second row
    Vector row = (Vector) data.elementAt(1);
    row = (Vector) row.clone();/*from  w  w  w. j a  v  a  2  s . c  o m*/

    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:TableSample2.java

public static void main(String args[]) {
    Object rows[][] = { { "one", "ichi - \u4E00", "un" }, { "two", "ni - \u4E8C", "deux" },
            { "three", "san - \u4E09", "trois" }, { "four", "shi - \u56DB", "quatre" },
            { "five", "go - \u4E94", "cinq" }, { "six", "roku - \u516D", "treiza" },
            { "seven", "shichi - \u4E03", "sept" }, { "eight", "hachi - \u516B", "huit" },
            { "nine", "kyu - \u4E5D", "neuf" }, { "ten", "ju - \u5341", "dix" } };
    Object options[] = { "un", "deux", "trois", "quatre", "cinq", "treiza", "sept", "huit", "neuf", "dix" };
    JComboBox comboBox = new JComboBox(options);
    comboBox.setMaximumRowCount(4);//from   w ww  . j ava2s. c o  m
    TableCellEditor editor = new DefaultCellEditor(comboBox);

    Object headers[] = { "English", "Japanese", "French" };
    JFrame frame = new JFrame("JTable Anatomy");
    class CustomTableModel extends DefaultTableModel {
        public CustomTableModel(Object rowData[][], Object columnNames[]) {
            super(rowData, columnNames);
        }

        public Class getColumnClass(int col) {
            Vector v = (Vector) dataVector.elementAt(0);
            return v.elementAt(col).getClass();
        }

        public boolean isCellEditable(int row, int col) {
            return true;
        }
    }
    JTable table = new JTable(new DefaultTableModel(rows, headers));

    //    ColumnModelUtilities.removeHeaders(table.getColumnModel());
    table.getColumnModel().getColumn(2).setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    Vector<Integer> vec = new Vector<Integer>(4);

    vec.add(4);/*from   ww w  . j a va  2  s. c  o  m*/
    vec.add(3);
    vec.add(2);
    vec.add(1);

    System.out.println(vec.elementAt(1));
}

From source file:MainClass.java

public static void main(String args[]) {

    Vector v = new Vector();

    for (int i = 0; i < 5; i++) {
        v.addElement(new Double(5));
    }/*from  w  w  w  .  ja  v  a 2s.  c  o m*/

    for (int i = v.size() - 1; i >= 0; i--) {
        System.out.print(v.elementAt(i) + " ");
    }
}

From source file:SafeVectorCopy.java

public static void main(String[] args) {
    Vector vect = new Vector();
    vect.addElement("Synchronization");
    vect.addElement("is");
    vect.addElement("important");

    String[] word;//ww w  .  ja va 2  s. c  o m

    synchronized (vect) {
        int size = vect.size();
        word = new String[size];

        for (int i = 0; i < word.length; i++) {
            word[i] = (String) vect.elementAt(i);
        }
    }

    System.out.println("word.length" + word.length);
    for (int i = 0; i < word.length; i++) {
        System.out.println("[" + i + "]=" + word[i]);
    }
}

From source file:SortWithCollationKeys.java

public static void main(String[] args) {
    Vector<String> list = new Vector<String>();
    list.add("m");
    list.add("c");
    list.add("e");
    list.add("c");

    Collator collate = Collator.getInstance();

    CollationKey[] keys = new CollationKey[list.size()];

    for (int k = 0; k < list.size(); k++)
        keys[k] = collate.getCollationKey((String) list.elementAt(k));

    CollationKey tmp;// w ww . j  a  v  a 2s  .co m
    for (int i = 0; i < keys.length; i++) {
        for (int j = i + 1; j < keys.length; j++) {
            if (keys[i].compareTo(keys[j]) > 0) {
                tmp = keys[i];
                keys[i] = keys[j];
                keys[j] = tmp;
            }
        }
    }
    for (int l = 0; l < keys.length; l++) {
        System.out.println(keys[l].getSourceString());
    }
}

From source file:ListCaptureDevices.java

public static void main(String[] args) {

    /////////////////////////////////////////////////////////////
    // Query CaptureDeviceManager about ANY capture devices (null
    // format)/*  w w  w  . ja v  a 2 s. com*/
    Vector info = CaptureDeviceManager.getDeviceList(null);
    if (info == null)
        System.out.println("No Capture devices known to JMF");
    else {
        System.out.println("The following " + info.size() + " capture devices are known to the JMF");
        for (int i = 0; i < info.size(); i++)
            System.out.println("\t" + (CaptureDeviceInfo) info.elementAt(i));
    }
}