List of usage examples for javax.swing.table DefaultTableCellRenderer setHorizontalAlignment
@BeanProperty(visualUpdate = true, enumerationValues = { "SwingConstants.LEFT", "SwingConstants.CENTER", "SwingConstants.RIGHT", "SwingConstants.LEADING", "SwingConstants.TRAILING" }, description = "The alignment of the label's content along the X axis.") public void setHorizontalAlignment(int alignment)
From source file:se.backede.jeconomix.forms.report.TransactionReport.java
public void setTableData(List<TransactionReportDto> calculatedReport) { DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); TransactionReportModel model = new TransactionReportModel(calculatedReport); reportTable.setModel(model);// ww w . j ava 2s . co m for (int i = 1; i < 14; i++) { reportTable.getColumnModel().getColumn(i).setCellRenderer(rightRenderer); } }
From source file:channel.metadata.ChannelMetadataPanel.java
/** * Initializes the panel// w w w . ja v a 2s.c om */ private void init() { setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]", "[grow,fill]")); mTable = new JTable(mChannelProcessingManager.getChannelMetadataModel()); DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) mTable.getDefaultRenderer(String.class); renderer.setHorizontalAlignment(SwingConstants.CENTER); mTable.getSelectionModel().addListSelectionListener(this); mTable.addMouseListener(new MouseSupport()); mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_STATE) .setCellRenderer(new ColoredStateCellRenderer()); mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_PRIMARY_TO) .setCellRenderer(new AliasedValueCellRenderer(Attribute.PRIMARY_ADDRESS_TO)); mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_PRIMARY_FROM) .setCellRenderer(new AliasedValueCellRenderer(Attribute.PRIMARY_ADDRESS_FROM)); mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_SECONDARY_TO) .setCellRenderer(new AliasedValueCellRenderer(Attribute.SECONDARY_ADDRESS_TO)); mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_SECONDARY_FROM) .setCellRenderer(new AliasedValueCellRenderer(Attribute.SECONDARY_ADDRESS_FROM)); JScrollPane scrollPane = new JScrollPane(mTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); add(scrollPane); // new TableColumnWidthMonitor(mTable, PROPERTY_PREFIX, new int[] {15,15,15,15,25,25,25,25,15,40}); }
From source file:StocksTable4.java
public StocksTable4() { super("Stocks Table"); setSize(600, 300);//w ww. ja v a 2 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(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); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:ExpenseReport.java
public ExpenseReport() { super("Expense Report"); setSize(570, 200);/*from ww w . j a va2s . c om*/ m_data = new ExpenseReportData(this); m_table = new JTable(); m_table.setAutoCreateColumnsFromModel(false); m_table.setModel(m_data); m_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); for (int k = 0; k < ExpenseReportData.m_columns.length; k++) { TableCellRenderer renderer; if (k == ExpenseReportData.COL_APPROVED) renderer = new CheckCellRenderer(); else { DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer(); textRenderer.setHorizontalAlignment(ExpenseReportData.m_columns[k].m_alignment); renderer = textRenderer; } TableCellEditor editor; if (k == ExpenseReportData.COL_CATEGORY) editor = new DefaultCellEditor(new JComboBox(ExpenseReportData.CATEGORIES)); else if (k == ExpenseReportData.COL_APPROVED) editor = new DefaultCellEditor(new JCheckBox()); else editor = new DefaultCellEditor(new JTextField()); TableColumn column = new TableColumn(k, ExpenseReportData.m_columns[k].m_width, renderer, editor); m_table.addColumn(column); } JTableHeader header = m_table.getTableHeader(); header.setUpdateTableInRealTime(false); JScrollPane ps = new JScrollPane(); ps.setSize(550, 150); ps.getViewport().add(m_table); getContentPane().add(ps, BorderLayout.CENTER); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); ImageIcon penny = new ImageIcon("penny.gif"); m_title = new JLabel("Total: $", penny, JButton.LEFT); m_title.setForeground(Color.black); m_title.setAlignmentY(0.5f); p.add(m_title); p.add(Box.createHorizontalGlue()); JButton bt = new JButton("Insert before"); bt.setMnemonic('b'); bt.setAlignmentY(0.5f); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row); m_table.tableChanged( new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Insert after"); bt.setMnemonic('a'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row + 1); m_table.tableChanged(new TableModelEvent(m_data, row + 1, row + 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Delete row"); bt.setMnemonic('d'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); if (m_data.delete(row)) { m_table.tableChanged(new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); calcTotal(); } } }; bt.addActionListener(lst); p.add(bt); getContentPane().add(p, BorderLayout.SOUTH); calcTotal(); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:net.sourceforge.happybank.main.BankMain.java
private void initComponents() { frame = new javax.swing.JFrame(); menuBar = new javax.swing.JMenuBar(); menuFile = new javax.swing.JMenu(); menuItemExit = new javax.swing.JMenuItem(); menuActions = new javax.swing.JMenu(); menuItemView = new javax.swing.JMenuItem(); separator2 = new javax.swing.JSeparator(); menuHelp = new javax.swing.JMenu(); separator4 = new javax.swing.JSeparator(); menuItemAbout = new javax.swing.JMenuItem(); accountEntries = new javax.swing.JTable(); accountModel = new AccountTableModel(); /*/* w w w . j a v a 2 s . c o m*/ * File menu */ menuFile.setMnemonic('F'); menuFile.setText("File"); // - Exit option menuItemExit.setMnemonic('X'); menuItemExit.setText("Exit"); menuItemExit.setActionCommand("Exit"); menuItemExit.addActionListener(new ActionHandler()); menuFile.add(menuItemExit); menuBar.add(menuFile); // Actions menu menuActions.setMnemonic('A'); menuActions.setText("Actions"); // - View option menuItemView.setMnemonic('V'); menuItemView .setAccelerator(KeyStroke.getKeyStroke('V', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menuItemView.setText("View"); menuItemView.setActionCommand("View"); menuItemView.addActionListener(new ActionHandler()); menuActions.add(menuItemView); menuActions.add(separator2); // Help menu menuHelp.setMnemonic('H'); menuHelp.setText("Help"); // - About option menuHelp.add(separator4); menuItemAbout.setMnemonic('A'); menuItemAbout.setText("About"); menuItemAbout.setActionCommand("About"); menuItemAbout.addActionListener(new ActionHandler()); menuHelp.add(menuItemAbout); menuBar.add(menuHelp); /* * configure the TabListCellRenderer */ accountEntries.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); accountEntries.setAutoCreateColumnsFromModel(false); accountEntries.setModel(accountModel); accountEntries.getTableHeader().setReorderingAllowed(false); accountEntries.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); accountEntries.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { // capture single click if (evt.getClickCount() == 1 && SwingUtilities.isLeftMouseButton(evt)) { // ignore } // capture double click if (evt.getClickCount() == 2) { // edit the account int row = accountEntries.rowAtPoint(evt.getPoint()); accountEntries.setRowSelectionInterval(row, row); onViewAccount(); } } // mouseClicked }); // MouseAdapter // set the column widths and alignment for (int k = 0; k < AccountTableModel.COLUMNS.length; k++) { TableCellEditor zipper = new DefaultCellEditor(new JTextField()); DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer(); textRenderer.setHorizontalAlignment(AccountTableModel.COLUMNS[k].cAlignment); TableColumn column = new TableColumn(k, AccountTableModel.COLUMNS[k].cWidth, textRenderer, zipper); accountEntries.addColumn(column); } // set the table header JTableHeader header = accountEntries.getTableHeader(); header.setUpdateTableInRealTime(false); /* * create the selection area */ accountPanel = new JPanel(); accountPanel.setLayout(new BorderLayout()); scrollPane = new JScrollPane(accountEntries); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new java.awt.Dimension(750, 300)); accountPanel.add(scrollPane); frame.getContentPane().add(accountPanel, java.awt.BorderLayout.CENTER); /* * layout the frame */ frame.setJMenuBar(menuBar); frame.setTitle(APP_NAME); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(screenSize.width / 2 - 300, screenSize.height / 2 - 200); // add a listener for the close event frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { onExit(); } }); loadAccounts(); }
From source file:org.pgptool.gui.ui.keyslist.KeysTableView.java
private void adjustColumnsWidths() { DefaultTableCellRenderer leftRenderer = new DefaultTableCellRenderer(); leftRenderer.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); leftRenderer.setHorizontalAlignment(JLabel.LEFT); DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment(JLabel.CENTER); adjustColumn(leftRenderer, KeysTableModel.COLUMN_USER, spacing(30), leftRenderer); adjustColumn(leftRenderer, KeysTableModel.COLUMN_KEY_ID, spacing(16), centerRenderer); adjustColumn(leftRenderer, KeysTableModel.COLUMN_KEY_TYPE, spacing(8), centerRenderer); adjustColumn(leftRenderer, KeysTableModel.COLUMN_ALGORITHM, spacing(13), centerRenderer); adjustColumn(leftRenderer, KeysTableModel.COLUMN_CREATED_ON, spacing(10), centerRenderer); adjustColumn(leftRenderer, KeysTableModel.COLUMN_EXPIRES_AT, spacing(10), centerRenderer); }
From source file:se.backede.jeconomix.forms.report.SingleTransactionReport.java
public void setTableData() { DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); TransactionCompanyModel transModel = new TransactionCompanyModel(new HashSet<>(reports.getTransctions())); transactionTable.setModel(transModel); transactionTable.getColumnModel().getColumn(2).setCellRenderer(rightRenderer); transactionSumLabel.setText(transModel.getSum().toString().concat(" Kr")); categoryNameLabel.setText(reports.getCategory()); }
From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatMultiplePanel.java
/** * // ww w . j a v a2 s . c om */ private void setFormatSwitchTblColumnProperties() { // set details of 1st column (field values) TableColumnModel model = formatSwitchTbl.getColumnModel(); TableColumn column = model.getColumn(model.getColumnIndex(FIELD_VALUE_COL)); column.setMinWidth(20); column.setMaxWidth(300); column.setPreferredWidth(70); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); column.setCellRenderer(renderer); // set details of 3rd column (ellipsis buttons) column = model.getColumn(model.getColumnIndex(ELLIPSIS_BUTTON_COL)); column.setCellRenderer(new EditDataObjFormatButtonRenderer()); column.setCellEditor(new EditDataObjFormatButtonEditor(createCheckBox())); column.setMinWidth(20); column.setMaxWidth(20); column.setPreferredWidth(20); }
From source file:se.backede.jeconomix.forms.report.SingleTransactionReport.java
public void filter() { companyComboBox.setEnabled(false);/* ww w . j av a 2 s .c om*/ yearComboBox.setEnabled(false); monthComboBox.setEnabled(false); LinkedList<TransactionDto> allTrasactions = new LinkedList<TransactionDto>(reports.getTransctions()); CompanyDto company = (CompanyDto) companyComboBox.getSelectedItem(); String yearString = (String) yearComboBox.getSelectedItem(); Integer year = Integer.parseInt("0"); if (yearString != null) { if (!yearString.equals(ALL_YEARS)) { year = Integer.parseInt(yearString); } } String monthString = (String) monthComboBox.getSelectedItem(); Month month = null; if (monthString != null) { if (!monthString.equals(ALL_MONTHS)) { month = Month.valueOf(monthString); } } LinkedList<TransactionDto> filteredCompanies = new LinkedList<>(reports.getTransctions()); if (company != null) { if (!company.getName().equals(ALL_COMPANIES)) { filteredCompanies = allTrasactions.stream().filter(line -> line.getCompany().equals(company)) .collect(Collectors.toCollection(LinkedList::new)); } } LinkedList<TransactionDto> filteredByYear = (LinkedList) filteredCompanies.clone(); if (yearString != null) { if (!yearString.equals(ALL_YEARS)) { for (TransactionDto filteredTransaction : filteredCompanies) { if (!Objects.equals(filteredTransaction.getBudgetYear(), year)) { filteredByYear.remove(filteredTransaction); } } } } LinkedList<TransactionDto> filteredByMonth = (LinkedList) filteredByYear.clone(); if (monthString != null) { if (!monthString.equals(ALL_MONTHS)) { for (TransactionDto filteredTransaction : filteredByYear) { if (filteredTransaction.getBudgetMonth() != month) { filteredByMonth.remove(filteredTransaction); } } } } DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); TransactionCompanyModel transModel = new TransactionCompanyModel(new HashSet<>(filteredByMonth)); transactionTable.setModel(transModel); transactionTable.getColumnModel().getColumn(2).setCellRenderer(rightRenderer); transactionSumLabel.setText(transModel.getSum().toString().concat(" Kr")); categoryNameLabel.setText(reports.getCategory()); companyComboBox.setEnabled(true); yearComboBox.setEnabled(true); monthComboBox.setEnabled(true); }
From source file:StocksTable5.java
public StocksTable5() { super("Stocks Table"); setSize(600, 300);/*from w w w . jav a2 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 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); }