List of usage examples for javax.swing JTable JTable
public JTable(TableModel dm)
JTable
that is initialized with dm
as the data model, a default column model, and a default selection model. From source file:MainClass.java
public MainClass() { super("Dynamic Data Test"); setSize(300, 200);/*from w w w . j a v a2s . co m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); JTable jt = new JTable(new MarketDataModel(5)); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:Main.java
public Main() { final AbstractTableModel model = new MyModel(); final JTable table = new JTable(model); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); model.setValueAt(new Integer(1), 0, 0); JButton button = new JButton("Increment selected cell"); getContentPane().add(button, BorderLayout.SOUTH); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); int column = table.convertColumnIndexToModel(table.getSelectedColumn()); int currentValue = ((Integer) model.getValueAt(row, column)).intValue(); model.setValueAt(new Integer(currentValue + 1), row, column); }/*from w ww . j a va 2s .c om*/ }); pack(); }
From source file:SetValueAtToSetValue.java
public SetValueAtToSetValue() { final AbstractTableModel model = new MyModel(); final JTable table = new JTable(model); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); model.setValueAt(new Integer(1), 0, 0); JButton button = new JButton("Increment selected cell"); getContentPane().add(button, BorderLayout.SOUTH); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); int column = table.convertColumnIndexToModel(table.getSelectedColumn()); int currentValue = ((Integer) model.getValueAt(row, column)).intValue(); model.setValueAt(new Integer(currentValue + 1), row, column); }/* w ww . j av a 2 s . c o m*/ }); pack(); }
From source file:Main.java
public Main() { DefaultTableModel m = new DefaultTableModel(new Object[][] { { "2", 2, 3 }, { "1", 4, 5 } }, new Object[] { 1, 2, 3 }); JTable t = new JTable(m); t.getColumnModel().getColumn(0)/*from ww w . ja va2 s. c om*/ .setCellEditor(new DefaultCellEditor(new JComboBox(new String[] { "1", "2" }))); t.getColumnModel().getColumn(0).setCellRenderer(getCellRenderer()); t.setRowHeight(25); getContentPane().add(new JScrollPane(t)); pack(); }
From source file:MainClass.java
public MainClass() { super("Custom TableModel Test"); setSize(300, 200);/*from ww w.j a v a 2 s.co m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); FileModel fm = new FileModel(); JTable jt = new JTable(fm); jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jt.setColumnSelectionAllowed(true); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:Main.java
public Main() { DefaultTableModel model = new DefaultTableModel(0, 5) { @Override//w w w . j a va2s . c om public boolean isCellEditable(int row, int column) { return false; } }; JTable table = new JTable(model); for (int i = 0; i < 20; i++) { model.addRow(new String[] { i + ".1", i + ".2", i + ".3", i + ".4", i + ".5", }); } add(table, BorderLayout.CENTER); table.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { System.out.println("pressed"); char key = e.getKeyChar(); int selectedColumn = table.getSelectedColumn(); for (int i = 0; i < model.getRowCount(); i++) { String value = (String) model.getValueAt(i, selectedColumn); model.setValueAt(value + key, i, selectedColumn); } } }); }
From source file:Main.java
public Main() { TableModel dataModel = new MyTableModel(); JTable table = new JTable(dataModel); table.setAutoCreateRowSorter(true);// w w w. j ava 2 s . c o m table.getColumnModel().getColumn(0).setPreferredWidth(100); table.getColumnModel().getColumn(1).setPreferredWidth(150); table.getColumnModel().getColumn(2).setPreferredWidth(200); JScrollPane jsp = new JScrollPane(table); this.add(jsp); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(model); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); pack();//from w w w .ja va 2s . c om }
From source file:ZipFileViewer.java
public ZipFileViewer(String zipFile, List zipEntries) { m_zipTableModel = new ZipTableModel(zipEntries); m_zipTable = new JTable(m_zipTableModel); JScrollPane scrollPane = new JScrollPane(m_zipTable); m_zipTable.setShowVerticalLines(true); m_zipTable.setShowHorizontalLines(false); getContentPane().add(scrollPane);// w w w .j a v a 2 s. c om setSize(800, 400); setVisible(true); }
From source file:FrozenColumnHeader.java
public FrozenColumnHeader(JTable table, int columns) { super();/*w w w .j av a 2 s . c o m*/ mainTable = table; headerTable = new JTable(mainTable.getModel()); getViewport().setView(headerTable); columnCount = columns; }