List of usage examples for javax.swing.table DefaultTableModel DefaultTableModel
public DefaultTableModel()
DefaultTableModel
which is a table of zero columns and zero rows. 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(); }// w ww . j ava2 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:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addColumn("Icon Here"); table.getColumnModel().getColumn(0).setHeaderValue(new ImageIcon("image.gif")); table.getColumnModel().getColumn(0).setHeaderRenderer(new IconHeaderRenderer()); }
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.addColumn("Col2"); table.getTableHeader().getColumnModel().getColumn(1).setHeaderRenderer(new IconHeaderRenderer()); table.getColumnModel().getColumn(1).setHeaderValue(new TextAndIcon("Col2", new ImageIcon("icon.gif"))); }
From source file:Main.java
private static JPanel createPanel() { JPanel panel = new JPanel(); DefaultTableModel model = new DefaultTableModel() { @Override//from ww w .j a va 2s .c o 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:ModelJTable.java
public ModelJTable() { super();//from w ww.jav a 2s. c o m model = new DefaultTableModel(); model.addColumn("First Name"); model.addColumn("Last Name"); model.addColumn("Years"); String[] socrates = { "Socrates", "", "469-399 B.C." }; model.addRow(socrates); String[] plato = { "Plato", "", "428-347 B.C." }; model.addRow(plato); String[] aquinas = { "Thomas", "Aquinas", "1225-1274" }; model.addRow(aquinas); String[] kierkegaard = { "Soren", "Kierkegaard", "1813-1855" }; model.addRow(kierkegaard); String[] kant = { "Immanuel", "Kant", "1724-1804" }; model.addRow(kant); String[] nietzsche = { "Friedrich", "Nietzsche", "1844-1900" }; model.addRow(nietzsche); String[] arendt = { "Hannah", "Arendt", "1906-1975" }; model.addRow(arendt); table = new JTable(model); JButton addButton = new JButton("Add Philosopher"); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String[] philosopher = { "", "", "" }; model.addRow(philosopher); } }); JButton removeButton = new JButton("Remove Selected Philosopher"); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { model.removeRow(table.getSelectedRow()); } }); JPanel inputPanel = new JPanel(); inputPanel.add(addButton); inputPanel.add(removeButton); Container container = getContentPane(); container.add(new JScrollPane(table), BorderLayout.CENTER); container.add(inputPanel, BorderLayout.NORTH); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(400, 300); setVisible(true); }
From source file:com.controller.CPMOrderMANIAC.java
public static TableModel getPRTableModel() { if (pendings.isEmpty()) { return new DefaultTableModel(); } else {//from w w w .j a v a2 s. c om ArrayList objList = (ArrayList) pendings; return new PMPendingRequestTableModel(objList); } }
From source file:com.controller.CTraderOrderMANIAC.java
public static TableModel getPRTableModel() { if (pendings.isEmpty()) { return new DefaultTableModel(); } else {/* w w w .jav a 2s. co m*/ ArrayList<SingleOrder> objList = (ArrayList) pendings; return new TraderPendingRequestsTableModel(objList); } }
From source file:com.controller.CPMOrderMANIAC.java
public static TableModel getOHTableModel() { if (executed.isEmpty()) { return new DefaultTableModel(); } else {//from www . j a v a2 s . c o m ArrayList<SingleOrder> objList = (ArrayList) executed; return new PMOrderHistoryTableModel(objList); } }
From source file:com.controller.CTraderOrderMANIAC.java
public static TableModel getBlockHistoryTableModel() { if (blockHistory.isEmpty()) { return new DefaultTableModel(); } else {// w w w. j a va2 s . co m ArrayList<Block> objList = (ArrayList) blockHistory; return new TraderBlockOrderHistoryTableModel(objList); } }
From source file:udea.edu.com.co.grafico.Graficas.java
/** * Creates new form Graficas//from w w w . j a v a2 s .com */ public Graficas() { initComponents(); this.setLocationRelativeTo(null); this.lineas.setVisible(false); this.setVisible(true); lineas.setVisible(true); capas.setLayer(lineas, 0, 0); modelo = new DefaultTableModel(); modelo.addColumn("X"); modelo.addColumn("Y"); this.datos.setModel(modelo); this.labelYk1.setVisible(false); this.textYk.setVisible(false); this.btnCalcularYk.setVisible(false); this.labelResultYk.setVisible(false); this.textResultYk.setVisible(false); }