List of usage examples for javax.swing JTable JTable
public JTable()
JTable
that is initialized with a default data model, a default column model, and a default selection model. From source file:StocksTable5.java
public StocksTable5() { super("Stocks Table"); setSize(600, 300);// w w w . ja va 2 s.c o m m_data = new StockTableData(); m_title = new JLabel(m_data.getTitle(), new ImageIcon("money.gif"), SwingConstants.LEFT); m_title.setFont(new Font("TimesRoman", Font.BOLD, 24)); m_title.setForeground(Color.black); getContentPane().add(m_title, BorderLayout.NORTH); m_table = new JTable(); m_table.setAutoCreateColumnsFromModel(false); m_table.setModel(m_data); for (int k = 0; k < StockTableData.m_columns.length; k++) { DefaultTableCellRenderer renderer = new ColoredTableCellRenderer(); renderer.setHorizontalAlignment(StockTableData.m_columns[k].m_alignment); TableColumn column = new TableColumn(k, StockTableData.m_columns[k].m_width, renderer, null); m_table.addColumn(column); } JTableHeader header = m_table.getTableHeader(); header.setUpdateTableInRealTime(true); header.addMouseListener(m_data.new ColumnListener(m_table)); header.setReorderingAllowed(true); JScrollPane ps = new JScrollPane(); ps.getViewport().add(m_table); getContentPane().add(ps, BorderLayout.CENTER); JMenuBar menuBar = createMenuBar(); setJMenuBar(menuBar); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:StocksTable.java
public StocksTable() { super("Stocks Table"); setSize(600, 300);/*from ww w . j ava 2 s .co m*/ m_data = new StockTableData(); m_title = new JLabel(m_data.getTitle(), new ImageIcon("money.gif"), SwingConstants.LEFT); m_title.setFont(new Font("TimesRoman", Font.BOLD, 24)); m_title.setForeground(Color.black); getContentPane().add(m_title, BorderLayout.NORTH); m_table = new JTable(); m_table.setAutoCreateColumnsFromModel(false); m_table.setModel(m_data); for (int k = 0; k < StockTableData.m_columns.length; k++) { DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(StockTableData.m_columns[k].m_alignment); TableColumn column = new TableColumn(k, StockTableData.m_columns[k].m_width, renderer, null); m_table.addColumn(column); } JTableHeader header = m_table.getTableHeader(); header.setUpdateTableInRealTime(false); JScrollPane ps = new JScrollPane(); ps.getViewport().add(m_table); getContentPane().add(ps, BorderLayout.CENTER); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:Main.java
public JComponent makeUI() { JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT); tabbedPane.setUI(new javax.swing.plaf.basic.BasicTabbedPaneUI() { @Override//from w ww .j ava2 s . co m protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) { return 32; } @Override protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) { if (tabIndex == 0) { rects[tabIndex].height = 30 + 1; rects[tabIndex].y = 32 - rects[tabIndex].height + 1; } else if (tabIndex == 1) { rects[tabIndex].height = 26 + 1; rects[tabIndex].y = 32 - rects[tabIndex].height + 1; } super.paintTab(g, tabPlacement, rects, tabIndex, iconRect, textRect); } }); tabbedPane.addTab("000", new JLabel("ok")); tabbedPane.addTab("111", new JScrollPane(new JTable())); tabbedPane.addTab("222", new JSplitPane()); return tabbedPane; }
From source file:StocksTable2.java
public StocksTable2() { super("Stocks Table"); setSize(600, 300);//from w w w .j a va2 s . c om m_data = new StockTableData(); m_title = new JLabel(m_data.getTitle(), new ImageIcon("money.gif"), SwingConstants.LEFT); m_title.setFont(new Font("TimesRoman", Font.BOLD, 24)); m_title.setForeground(Color.black); getContentPane().add(m_title, BorderLayout.NORTH); m_table = new JTable(); m_table.setAutoCreateColumnsFromModel(false); m_table.setModel(m_data); for (int k = 0; k < StockTableData.m_columns.length; k++) { DefaultTableCellRenderer renderer = new ColoredTableCellRenderer(); renderer.setHorizontalAlignment(StockTableData.m_columns[k].m_alignment); TableColumn column = new TableColumn(k, StockTableData.m_columns[k].m_width, renderer, null); m_table.addColumn(column); } JTableHeader header = m_table.getTableHeader(); header.setUpdateTableInRealTime(false); JScrollPane ps = new JScrollPane(); ps.getViewport().add(m_table); getContentPane().add(ps, BorderLayout.CENTER); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:Main.java
public MyTableInTreeCellRenderer() { super(new BorderLayout()); table = new JTable(); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane);/*from ww w . j av a2s. c o m*/ }
From source file:ColorTableColumnRenderer.java
public ColorTableColumnRenderer() { super("Stocks Table"); setSize(300, 300);/*from w ww . j a v a2 s . c o m*/ tableModel = new MyTableModel(); table = new JTable(); table.setModel(tableModel); DefaultTableCellRenderer renderer = new ColoredTableCellRenderer(); TableColumn column = new TableColumn(0, 190, renderer, null); table.addColumn(column); JScrollPane ps = new JScrollPane(); ps.getViewport().add(table); getContentPane().add(ps, BorderLayout.CENTER); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java
public DocumentTable(final Gui gui, final SecureStore store) { this.gui = gui; this.store = store; this.table = new JTable(); this.table.setRowSelectionAllowed(true); this.refreshContents(); this.table.addMouseListener(new MouseAdapter() { @Override/*from w ww . j a v a2 s . c o m*/ public void mousePressed(final MouseEvent me) { final int r = DocumentTable.this.table.rowAtPoint(me.getPoint()); if (!DocumentTable.this.table.getSelectionModel().isSelectedIndex(r)) { if (r >= 0 && r < DocumentTable.this.table.getRowCount()) { DocumentTable.this.table.setRowSelectionInterval(r, r); } else { DocumentTable.this.table.clearSelection(); } } if (me.isPopupTrigger()) { DocumentTable.this.showPopup(me); } else if (me.getClickCount() == 2) { DocumentTable.this.openSelectedRows(); } } @Override public void mouseReleased(final MouseEvent me) { if (me.isPopupTrigger()) { DocumentTable.this.showPopup(me); } } }); this.table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); this.table.getColumnModel().getColumn(0).setPreferredWidth(120); this.table.getColumnModel().getColumn(1).setPreferredWidth(80); this.table.getColumnModel().getColumn(2).setPreferredWidth(100); this.table.getColumnModel().getColumn(3).setPreferredWidth(500); }
From source file:edu.harvard.mcz.imagecapture.VerbatimToTranscribeDialog.java
/** * Create the dialog.// w ww .j a va 2s. c o m */ public VerbatimToTranscribeDialog() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); setBounds(100, 100, 726, 557); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new BorderLayout(0, 0)); { table = new JTable(); SpecimenLifeCycle sls = new SpecimenLifeCycle(); GenusSpeciesCountTableModel model = new GenusSpeciesCountTableModel(sls.countSpecimensForVerbatim()); table.setModel(model); table.setDefaultRenderer(GenusSpeciesCount.class, new ButtonRenderer("Transcribe")); table.setDefaultEditor(GenusSpeciesCount.class, new ButtonEditor(ButtonEditor.OPEN_SPECIMEN_VERBATIM, this)); contentPanel.add(table, BorderLayout.CENTER); } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton cancelButton = new JButton("Close"); cancelButton.setActionCommand("Close"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); buttonPane.add(cancelButton); } } }
From source file:controlador.ControladorReportes.java
public ControladorReportes(Reporte reportes) { this.reportes = reportes; selectorReporte = new TipoReporte(new javax.swing.JFrame(), true); reporteDAO = new ReportesDAO(); graficoDAO = new GraficoDAO(); setListeners();// w ww . j a v a 2 s. co m tablaLibros = new JTable(); tablaModelo = (DefaultTableModel) tablaLibros.getModel(); totalTabla = ""; inicializarTablasReportes(); }
From source file:com.floreantpos.ui.views.CookingInstructionSelectionView.java
private void createUI() { setTitle(Messages.getString("CookingInstructionSelectionView.1")); setTitlePaneText(Messages.getString("CookingInstructionSelectionView.1")); //$NON-NLS-1$ getContentPanel().setBorder(new EmptyBorder(10, 20, 0, 20)); JScrollPane scrollPane = new JScrollPane(); table = new JTable(); table.setRowHeight(35);//w w w .ja v a 2 s. com scrollPane.setViewportView(table); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int index = table.getSelectedRow(); if (index < 0) return; CookingInstructionTableModel model = (CookingInstructionTableModel) table.getModel(); CookingInstruction cookingInstruction = model.rowsList.get(index); tfCookingInstruction.setText(cookingInstruction.getDescription()); } }); tfCookingInstruction.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { doFilter(); } @Override public void keyReleased(KeyEvent e) { doFilter(); } @Override public void keyPressed(KeyEvent e) { } }); PosButton btnSave = new PosButton(IconFactory.getIcon("save.png")); btnSave.setText(POSConstants.SAVE.toUpperCase()); btnSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String instruction = tfCookingInstruction.getText(); if (instruction == null || instruction.isEmpty()) { POSMessageDialog.showMessage(Application.getPosWindow(), "Instruction cannot be empty."); return; } CookingInstruction cookingInstruction = new CookingInstruction(); cookingInstruction.setDescription(instruction); CookingInstructionDAO.getInstance().save(cookingInstruction); updateView(); CookingInstructionTableModel model = (CookingInstructionTableModel) table.getModel(); table.getSelectionModel().addSelectionInterval(model.getRowCount() - 1, model.getRowCount() - 1); } }); JPanel contentPanel = new JPanel(new MigLayout("fill,wrap 1,inset 0")); contentPanel.add(scrollPane, "grow"); contentPanel.add(tfCookingInstruction, "h 35!,split 2,grow"); contentPanel.add(btnSave, "h 35!,w 90!"); QwertyKeyPad keyPad = new QwertyKeyPad(); contentPanel.add(keyPad, "grow"); getContentPanel().add(contentPanel); }