package programa; import java.awt.* ; import java.util.Vector; import javax.swing.* ; import javax.swing.table.AbstractTableModel; /** * * @author kestaz */ public class Main { public static void main(String[] args) { JFrame window = new App() ; window.setVisible(true); } } class App extends JFrame { protected JTable table ; protected InteractiveTabelModel tableModel ; public String[] columnNames = { "Title", "Artist", "Album" } ; App() { Container content = getContentPane() ; //JPanel content = new JPanel() ; // setContentPane(content); setTitle("CD Katalogas") ; setSize(400, 200) ; setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); content.setLayout(new BorderLayout()); tableModel = new InteractiveTabelModel(columnNames) ; table = new JTable() ; table.setModel(tableModel) ; // JPanel rightPanel = new JPanel() ; JScrollPane scrollPane = new JScrollPane(table) ; content.add(table, BorderLayout.WEST) ; content.add(table.getTableHeader(), BorderLayout.PAGE_START) ; //content.add(testButton, BorderLayout.CENTER) //content.add(rightPanel, BorderLayout.CENTER) ; } } class InteractiveTabelModel extends AbstractTableModel { protected String[] columnNames ; protected Vector dataVector ; public InteractiveTabelModel(String [] column) { columnNames = column ; dataVector = new Vector() ; } public int getRowCount() { return dataVector.size() ; } public int getColumnCount() { return columnNames.length ; } public Object getValueAt(int rowIndex, int columnIndex) { /* CdRecord record = (CdRecord) dataVector.get(rowIndex) ; switch(columnIndex) { case 0: return record.getTitle() ; case 1: return record.getArtist() ; case 2: return record.getAlbum() ; default: return new Object() ; } * */ return null ; } @Override public String getColumnName (int column) { return columnNames[column] ; } } class CdRecord { protected String title ; protected String artist ; protected String album ; public CdRecord() { title = "" ; artist = "" ; album = "" ; } public String getTitle() { return title ; } public String getArtist() { return artist ; } public String getAlbum() { return album ; } }