Example usage for javax.swing.table DefaultTableModel addRow

List of usage examples for javax.swing.table DefaultTableModel addRow

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableModel addRow.

Prototype

public void addRow(Object[] rowData) 

Source Link

Document

Adds a row to the end of the model.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    DefaultTableModel model = new DefaultTableModel(null, new String[] { "CheckMe", "Value" }) {
        public Class getColumnClass(int c) {
            switch (c) {
            case 0:
                return Boolean.class;
            default:
                return String.class;
            }/*from  w  ww .  j  a v a2s . c o m*/
        }
    };
    JTable table = new JTable(model);
    JFrame frame = new JFrame("CheckBox Test");
    frame.add(table);
    model.addRow(new Object[] { true, "This is true" });
    model.addRow(new Object[] { false, "This is false" });
    frame.pack();
    frame.validate();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) {
    DefaultTableModel model = new DefaultTableModel() {
        public Class getColumnClass(int mColIndex) {
            int rowIndex = 0;
            Object o = getValueAt(rowIndex, mColIndex);
            if (o == null) {
                return Object.class;
            } else {
                return o.getClass();
            }//from   w  ww  . j  a  va  2 s . c o  m
        }
    };
    JTable table = new JTable(model);
    model.addColumn("Col1", new Object[] { Color.red });
    model.addRow(new Object[] { Color.green });
    model.addRow(new Object[] { Color.blue });

    table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());

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

From source file:MainWindowLogic.java

static void inputValuesIntoTableFromDataForwarder(Point2D[] pointsCollection, JTable jTabela) {
    DefaultTableModel tmp = (DefaultTableModel) jTabela.getModel();
    for (Point2D point : pointsCollection) {
        tmp.addRow(new Object[] { (tmp.getRowCount() + 1) + ".", point.getX(), point.getY(), false });
    }//  w  ww . ja v  a2s . c  om
}

From source file:MainWindowLogic.java

static void addRowToTable(JTable where) {
    DefaultTableModel tmp = (DefaultTableModel) where.getModel();
    int acutalsize = tmp.getRowCount();
    acutalsize++;/*from w  ww .ja v a 2 s.  c  o m*/
    tmp.addRow(new Object[] { acutalsize + ".", 0.0, 0.0, false });
}

From source file:MainWindowLogic.java

static void readPointsFile(File fil_hndl, JTable tabela) throws IOException, InvalidFormatInFileException {
    ReadPointsFromFile pointsReader = new ReadPointsFromFile(fil_hndl.getPath());
    System.out.println("cieka wcztytywanego pliku: " + fil_hndl.getPath());
    Point2D[] readed = pointsReader.readPoints();

    DefaultTableModel defaultModelTabeli = (DefaultTableModel) tabela.getModel();

    for (Point2D point : readed) {
        defaultModelTabeli.addRow(
                new Object[] { defaultModelTabeli.getRowCount() + 1 + ".", point.getX(), point.getY(), false });
    }//from w w w  . j av a 2 s .  c om

}

From source file:utils.UtilsFunction.java

public static void addARowToAModel(DefaultTableModel model, Student s) {
    Object[] rowData = { s.getId(), s.getName(), s.getAddress(), s.getAge(), s.getGender(), s.getEmail(),
            s.getPhoneNumber(), s.getBirthday(), s.getStudent_class() };
    model.addRow(rowData);
}

From source file:FindHullWindowLogic.java

static public void fullfilTableWithConvexHull(JTable jTableDest, ArrayList<Point2D> convexHull) {
    DefaultTableModel jTableDestModel = (DefaultTableModel) jTableDest.getModel();
    jTableDestModel.setRowCount(0);//from   w w w .  j a va 2 s  . c  om

    int i = 1;
    for (Point2D onePoint : convexHull) {
        if (i != 1 && areTheSamePoints(onePoint, convexHull.get(0)))
            break;
        jTableDestModel.addRow(new Object[] { i + ".", onePoint.getX(), onePoint.getY() });
        i++;
    }

}

From source file:Main.java

private static JPanel createPanel() {
    JPanel panel = new JPanel();
    DefaultTableModel model = new DefaultTableModel() {
        @Override/*w ww .j a  va  2  s  . co m*/
        public Class<?> getColumnClass(int col) {
            if (col == 0) {
                return Icon.class;
            } else {
                return Double.class;
            }
        }
    };
    model.setColumnIdentifiers(new Object[] { "Book", "Cost" });
    for (int i = 0; i < 42; i++) {
        model.addRow(new Object[] { ICON, Double.valueOf(i) });
    }
    JTable table = new JTable(model);
    table.setDefaultRenderer(Double.class, new DefaultTableCellRenderer() {
        @Override
        protected void setValue(Object value) {
            NumberFormat format = NumberFormat.getCurrencyInstance();
            setText((value == null) ? "" : format.format(value));
        }
    });
    table.setRowHeight(ICON.getIconHeight());
    panel.add(new JScrollPane(table) {
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(320, 240);
        }
    });
    return panel;
}

From source file:at.nullpointer.trayrss.gui.tablemodel.TableModelFactory.java

public static DefaultTableModel getTableModel(Set<Feed> feeds) {

    DefaultTableModel tableModel = new DefaultTableModel(getHeader(), 0) {

        Class[] columnTypes = new Class[] { String.class, String.class, Long.class, Boolean.class };

        public Class<?> getColumnClass(int columnIndex) {

            return columnTypes[columnIndex];
        }/*from ww w.  j  a  va2  s  .  co  m*/

        boolean[] columnEditables = new boolean[] { false, false, false, false };

        public boolean isCellEditable(int row, int column) {

            return columnEditables[column];
        }
    };

    for (Feed feed : feeds) {
        tableModel.addRow(feedToObjectRow(feed));
    }

    return tableModel;

}

From source file:cz.muni.fi.mushroomhunter.restclient.LocationCreateSwingWorker.java

@Override
protected void done() {
    try {/*from  w  ww.ja v  a 2 s .c  o  m*/
        get();
    } catch (Exception e) {
        restClient.getlMessageLocations().setText("ERROR: server is unavailable.");
        return;
    }
    DefaultTableModel model = (DefaultTableModel) restClient.getTblLocation().getModel();
    model.addRow(new Object[] { restClient.getTfLocationName().getText(),
            restClient.getTfLocationDescription().getText(), restClient.getTfLocationNearCity().getText() });
}