Java Code Examples for javax.swing.table.JTableHeader#setDefaultRenderer()
The following examples show how to use
javax.swing.table.JTableHeader#setDefaultRenderer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
private MainPanel() { super(new BorderLayout()); JTable table = new JTable(makeModel()); table.setFillsViewportHeight(true); table.setRowSelectionAllowed(true); table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setComponentPopupMenu(new TablePopupMenu(table)); JTableHeader header = table.getTableHeader(); header.setDefaultRenderer(new SortButtonRenderer()); header.addMouseListener(new HeaderMouseListener()); // header.setReorderingAllowed(false); TableColumn col = table.getColumnModel().getColumn(0); col.setMinWidth(80); col.setMaxWidth(80); add(new JScrollPane(table)); add(makeToolBar(table), BorderLayout.NORTH); setPreferredSize(new Dimension(320, 240)); }
Example 2
Source File: ListTable.java From consulo with Apache License 2.0 | 6 votes |
public ListTable(ListWrappingTableModel tableModel) { super(tableModel); setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS); setRowSelectionAllowed(true); setDragEnabled(false); final JTableHeader header = getTableHeader(); header.setReorderingAllowed(false); final TableCellRenderer delegate = header.getDefaultRenderer(); final TableCellRenderer newRenderer = new TableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component component = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); // to display the table header in disabled state when the table is disabled. component.setEnabled(table.isEnabled()); return component; } }; header.setDefaultRenderer(newRenderer); setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); }
Example 3
Source File: UpdateUIRecursionTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public UpdateUIRecursionTest() { super("UpdateUIRecursionTest"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 400); String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian"}; Object[][] data = { {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)}, {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)}, {"Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false)}, {"Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true)}, {"Philip", "Milne", "Pool", new Integer(10), new Boolean(false)} }; JTableHeader tableHeader = new JTableHeader(); table = new JTable(data, columnNames); table.setTableHeader(tableHeader); tableHeader.setDefaultRenderer(this); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); setVisible(true); }
Example 4
Source File: GameStatisticsGUI.java From Carcassonne with Eclipse Public License 2.0 | 5 votes |
private void buildTable(Round round) { table = new JTable(new GameStatisticsModel(round)); // Columns: TableColumnModel model = table.getColumnModel(); CellRenderer renderer = new CellRenderer(round); for (int i = 0; i < model.getColumnCount(); i++) { model.getColumn(i).setCellRenderer(renderer); } // Header: JTableHeader header = table.getTableHeader(); header.setDefaultRenderer(new HeaderRenderer()); header.setReorderingAllowed(false); table.setBackground(BODY_COLOR); }
Example 5
Source File: MaterialTableHeaderUI.java From material-ui-swing with MIT License | 5 votes |
@Override public void installUI (JComponent c) { super.installUI (c); JTableHeader header = (JTableHeader) c; header.setDefaultRenderer (new MaterialTableHeaderCellRenderer ()); header.setBackground(UIManager.getColor("TableHeader.background")); header.setForeground(UIManager.getColor("TableHeader.foreground")); header.setFont(UIManager.getFont("TableHeader.font")); header.setBorder(UIManager.getBorder("TableHeader.border")); }
Example 6
Source File: MaterialTableHeaderUI.java From material-ui-swing with MIT License | 5 votes |
@Override public void uninstallUI(JComponent c) { JTableHeader header = (JTableHeader) c; header.setDefaultRenderer (null); header.setBackground(null); header.setForeground(null); header.setFont(null); header.setBorder(null); super.uninstallUI(c); }
Example 7
Source File: UPbFractionTable.java From ET_Redux with Apache License 2.0 | 5 votes |
/** * * @param myFrame * @param mySample */ public void setMySample(ETReduxFrame myFrame, SampleInterface mySample) { this.mySample = mySample; setModel(new UPbFractionTableModel(myFrame, mySample)); JTableHeader header = getTableHeader(); header.setReorderingAllowed(false); float[] myLightBlue = Color.RGBtoHSB(241, 246, 254, null); header.setBackground(Color.getHSBColor(myLightBlue[0], myLightBlue[1], myLightBlue[2])); header.setDefaultRenderer(new HeaderCellRendererToLabel()); }
Example 8
Source File: AccountsPanel.java From btdex with GNU General Public License v3.0 | 4 votes |
public AccountsPanel(Main main) { super(new BorderLayout()); this.main = main; table = new JTable(model = new DefaultTableModel(COLUMN_NAMES, 0)); for (int i = 0; i < COLUMN_NAMES.length; i++) { table.getColumnModel().getColumn(i).setHeaderValue(tr(COLUMN_NAMES[i])); } table.setRowHeight(table.getRowHeight()+7); table.setPreferredScrollableViewportSize(new Dimension(400, 200)); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(this); left = new JPanel(new BorderLayout()); right = new JPanel(); right.setVisible(false); right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS)); left.setBorder(BorderFactory.createTitledBorder(tr("acc_your_accounts"))); right.setBorder(BorderFactory.createTitledBorder(tr("acc_account_details"))); JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true); // Center header and all columns DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment( JLabel.CENTER ); for (int i = 0; i < table.getColumnCount(); i++) { table.getColumnModel().getColumn(i).setCellRenderer( centerRenderer ); } JTableHeader jtableHeader = table.getTableHeader(); DefaultTableCellRenderer rend = (DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer(); rend.setHorizontalAlignment(JLabel.CENTER); jtableHeader.setDefaultRenderer(rend); table.setAutoCreateColumnsFromModel(false); table.getColumnModel().getColumn(COL_NAME).setPreferredWidth(200); table.getColumnModel().getColumn(COL_MARKET).setPreferredWidth(20); JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); left.add(buttonPane, BorderLayout.PAGE_END); addButton = new JButton(tr("acc_add_button")); removeButton = new JButton(tr("acc_remove_button")); removeButton.setEnabled(false); addButton.addActionListener(this); removeButton.addActionListener(this); buttonPane.add(addButton); buttonPane.add(removeButton); marketComboBox = new JComboBox<Market>(); for(Market m : Markets.getMarkets()) { if(m.getTokenID()!=null) continue; marketComboBox.addItem(m); } marketComboBox.addActionListener(this); JPanel topPanel = new JPanel(new SpringLayout()); topPanel.add(new Desc(tr("main_market"), marketComboBox), BorderLayout.LINE_START); topPanel.add(new Desc(tr("acc_alias"), nameField = new JTextField()), BorderLayout.CENTER); SpringUtilities.makeCompactGrid(topPanel, 1, 2, 0, 0, PAD, PAD); right.add(topPanel); formPanel = new JPanel(new SpringLayout()); // JScrollPane formScroll = new JScrollPane(formPanel); // right.add(formScroll); right.add(formPanel); cancelButton = new JButton(tr("dlg_cancel")); okButton = new JButton(tr("dlg_ok")); cancelButton.addActionListener(this); okButton.addActionListener(this); rightButtonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); rightButtonPane.add(cancelButton); rightButtonPane.add(okButton); right.add(rightButtonPane); add(left, BorderLayout.LINE_START); JPanel rightContainer = new JPanel(new BorderLayout()); rightContainer.add(right, BorderLayout.PAGE_START); add(rightContainer, BorderLayout.CENTER); left.add(scrollPane, BorderLayout.CENTER); loadAccounts(); }
Example 9
Source File: TransactionsPanel.java From btdex with GNU General Public License v3.0 | 4 votes |
public TransactionsPanel() { super(new BorderLayout()); table = new JTable(model = new MyTableModel()); table.setRowHeight(table.getRowHeight()+10); table.setRowSelectionAllowed(false); table.getTableHeader().setReorderingAllowed(false); copyIcon = IconFontSwing.buildIcon(Icons.COPY, 12, table.getForeground()); expIcon = IconFontSwing.buildIcon(Icons.EXPLORER, 12, table.getForeground()); JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true); // Center header and all columns DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment( JLabel.CENTER ); for (int i = 0; i < table.getColumnCount(); i++) { table.getColumnModel().getColumn(i).setCellRenderer( centerRenderer ); } JTableHeader jtableHeader = table.getTableHeader(); DefaultTableCellRenderer rend = (DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer(); rend.setHorizontalAlignment(JLabel.CENTER); jtableHeader.setDefaultRenderer(rend); table.setAutoCreateColumnsFromModel(false); table.getColumnModel().getColumn(COL_ID).setCellRenderer(OrderBook.BUTTON_RENDERER); table.getColumnModel().getColumn(COL_ID).setCellEditor(OrderBook.BUTTON_EDITOR); table.getColumnModel().getColumn(COL_ACCOUNT).setCellRenderer(OrderBook.BUTTON_RENDERER); table.getColumnModel().getColumn(COL_ACCOUNT).setCellEditor(OrderBook.BUTTON_EDITOR); // table.getColumnModel().getColumn(COL_ACCOUNT).setPreferredWidth(200); table.getColumnModel().getColumn(COL_ID).setPreferredWidth(200); table.getColumnModel().getColumn(COL_TIME).setPreferredWidth(120); statusLabel = new JLabel(" ", JLabel.RIGHT); statusLabel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); add(statusLabel, BorderLayout.PAGE_START); add(scrollPane, BorderLayout.CENTER); }
Example 10
Source File: JSortTable.java From tn5250j with GNU General Public License v2.0 | 4 votes |
private void initSortHeader() { JTableHeader header = getTableHeader(); header.setDefaultRenderer(new SortHeaderRenderer()); header.addMouseListener(this); }