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:Main.java
public Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); String[] columns = { "Item", "Price" }; Object[][] rows = { { "Potatoes", 10.98 }, { "Magazine", 7.99 }, { "Can of soup", 0.89 }, { "DVD movie", 39.99 } }; TableModel model = new DefaultTableModel(rows, columns) { public Class getColumnClass(int column) { if (column >= 0 && column <= getColumnCount()) return getValueAt(0, column).getClass(); else/* w w w.ja v a 2 s . c om*/ return Object.class; } }; JTable table = new JTable(model); RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); getContentPane().add(new JScrollPane(table)); setSize(200, 150); setVisible(true); }
From source file:TableRowSorterWithHeader.java
public TableRowSorterWithHeader() { setDefaultCloseOperation(EXIT_ON_CLOSE); String[] columns = { "Item", "Price" }; Object[][] rows = { { "Potatoes", 10.98 }, { "Magazine", 7.99 }, { "Can of soup", 0.89 }, { "DVD movie", 39.99 } }; TableModel model = new DefaultTableModel(rows, columns) { public Class getColumnClass(int column) { if (column >= 0 && column <= getColumnCount()) return getValueAt(0, column).getClass(); else// w ww.j a v a2 s. c o m return Object.class; } }; JTable table = new JTable(model); RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); getContentPane().add(new JScrollPane(table)); setSize(200, 150); setVisible(true); }
From source file:MainClass.java
public MainClass() { setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(350, 200);//from w w w . j a v a2 s. c om JTable table = new JTable(qtm); JScrollPane scrollpane = new JScrollPane(table); JPanel commandPanel = new JPanel(); commandPanel.setLayout(new GridLayout(3, 2)); commandPanel.add(new JLabel("Enter the Host URL: ")); commandPanel.add(hostField = new JTextField()); commandPanel.add(new JLabel("Enter your query: ")); commandPanel.add(queryField = new JTextField()); commandPanel.add(new JLabel("Click here to send: ")); JButton jb = new JButton("Search"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { qtm.setHostURL(hostField.getText().trim()); qtm.setQuery(queryField.getText().trim()); } }); commandPanel.add(jb); getContentPane().add(commandPanel, BorderLayout.NORTH); getContentPane().add(scrollpane, BorderLayout.CENTER); }
From source file:NewFilterTable.java
public NewFilterTable() { setDefaultCloseOperation(EXIT_ON_CLOSE); String[] columns = { "ID", "Des", "Date", "Fixed" }; Object[][] rows = { { 1, "C", new Date(), new Date() }, { 2, "G", new Date(), new Date() }, { 5, "F", new Date(), new Date() } }; TableModel model = new DefaultTableModel(rows, columns); JTable table = new JTable(model); final TableRowSorter<TableModel> sorter; sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);/*from ww w .j a va 2 s. c o m*/ getContentPane().add(new JScrollPane(table)); JPanel pnl = new JPanel(); pnl.add(new JLabel("Filter expression:")); final JTextField txtFE = new JTextField(25); pnl.add(txtFE); JButton btnSetFE = new JButton("Set Filter Expression"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { String expr = txtFE.getText(); sorter.setRowFilter(RowFilter.regexFilter(expr)); sorter.setSortKeys(null); } }; btnSetFE.addActionListener(al); pnl.add(btnSetFE); getContentPane().add(pnl, BorderLayout.SOUTH); setSize(750, 150); setVisible(true); }
From source file:FileTable2.java
public FileTable2() { super("Custom TableModel Test"); setSize(300, 200);/*www. 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); jt.setDefaultRenderer(Number.class, new BigRenderer(1000)); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:MainClass.java
public MainClass() { super("Customer Editor Test"); setSize(600, 160);//from w w w . ja v a 2s . c o m setDefaultCloseOperation(EXIT_ON_CLOSE); MixerModel test = new MixerModel(); JTable jt = new JTable(test); jt.setDefaultRenderer(Volume.class, new VolumeRenderer()); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:IsEDTExample.java
public IsEDTExample() { JTable table = new JTable(tableModel); table.setRowHeight(100);/*from www . j a v a2s .c o m*/ table.setDefaultRenderer(Object.class, new ColorRenderer()); add(table); add(new JLabel("Thread Color Shade:")); ButtonGroup group = new ButtonGroup(); JRadioButton redOption = new JRadioButton("Red"); group.add(redOption); redOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = RED; } }); JRadioButton blueOption = new JRadioButton("Blue"); group.add(blueOption); blueOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = BLUE; } }); JRadioButton greenOption = new JRadioButton("Green"); group.add(greenOption); greenOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = GREEN; } }); redOption.setSelected(true); this.threadShade = RED; add(redOption); add(greenOption); add(blueOption); add(new JButton(new RandomColorAction())); this.keepRunning = true; this.colorShadeThread = new Thread(new RandomColorShadeRunnable()); this.colorShadeThread.start(); }
From source file:NumberViewer.java
public NumberViewer() { tableModel = new LocaleTableModel(); JTable table = new JTable(tableModel); add(new JScrollPane(table)); }
From source file:PagingTester.java
public PagingTester() { super("Paged JTable Test"); setSize(300, 200);/* w w w. j a v a2 s . c om*/ setDefaultCloseOperation(EXIT_ON_CLOSE); PagingModel pm = new PagingModel(); JTable jt = new JTable(pm); // Use our own custom scrollpane. JScrollPane jsp = PagingModel.createPagingScrollPaneForTable(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:MarketTable.java
public MarketTable() { super("Dynamic Data Test"); setSize(300, 200);// w ww . j av a 2 s . c o m setDefaultCloseOperation(EXIT_ON_CLOSE); // Set up our table model with a 5-second polling delay MarketDataModel mdm = new MarketDataModel(5); // Pick which stocks we want to watch . . . mdm.setStocks(new int[] { 0, 1, 2 }); // And pop up the table JTable jt = new JTable(mdm); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }