Search in sources :

Example 81 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project Eidolons by IDemiurge.

the class DC_InfoPanelRenderer method getDefaultComp.

private Component getDefaultComp(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Component component = new DefaultTableCellRenderer().getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (value.toString().equals(G_PROPS.EMPTY_VALUE.toString()) || table.getValueAt(row, 0).toString().equals(G_PROPS.EMPTY_VALUE.toString())) {
        component = new DefaultTableCellRenderer().getTableCellRendererComponent(table, "", false, hasFocus, row, column);
        component.setBackground(Color.BLACK);
        table.setRowHeight(row, table.getRowHeight() / 2);
        return component;
    }
    return component;
}
Also used : DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 82 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project CoreNLP by stanfordnlp.

the class InputPanel method showHistory.

private void showHistory() {
    if (historyFrame == null) {
        historyFrame = new JFrame("Statistics History");
    } else {
        historyFrame.setVisible(false);
        historyFrame = new JFrame("Statistics History");
    }
    historyFrame.setLayout(new GridLayout(1, 0));
    Object[][] entries = new Object[historyList.size()][3];
    for (int i = 0; i < historyList.size(); i++) {
        entries[i] = historyList.get(i).toArray();
    }
    DefaultTableModel tableModel = new TregexGUITableModel(entries, HistoryEntry.columnNamesArray());
    JTable statTable = new JTable(tableModel);
    DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) statTable.getDefaultRenderer(String.class);
    dtcr.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
    JScrollPane scroller = new JScrollPane(statTable);
    historyFrame.add(scroller);
    historyFrame.pack();
    historyFrame.setLocationRelativeTo(TregexGUI.getInstance());
    historyFrame.setBackground(Color.WHITE);
    historyFrame.setVisible(true);
    historyFrame.repaint();
}
Also used : GridLayout(java.awt.GridLayout) DefaultTableModel(javax.swing.table.DefaultTableModel) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 83 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project gitblit by gitblit.

the class RepositoriesPanel method initialize.

private void initialize() {
    final JButton browseRepository = new JButton(Translation.get("gb.browse"));
    browseRepository.setEnabled(false);
    browseRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            RepositoryModel model = getSelectedRepositories().get(0);
            String url = gitblit.getURL("summary", model.name, null);
            Utils.browse(url);
        }
    });
    JButton refreshRepositories = new JButton(Translation.get("gb.refresh"));
    refreshRepositories.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshRepositories();
        }
    });
    clearCache = new JButton(Translation.get("gb.clearCache"));
    clearCache.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            clearCache();
        }
    });
    createRepository = new JButton(Translation.get("gb.create"));
    createRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            createRepository();
        }
    });
    editRepository = new JButton(Translation.get("gb.edit"));
    editRepository.setEnabled(false);
    editRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editRepository(getSelectedRepositories().get(0));
        }
    });
    delRepository = new JButton(Translation.get("gb.delete"));
    delRepository.setEnabled(false);
    delRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            deleteRepositories(getSelectedRepositories());
        }
    });
    final JButton subscribeRepository = new JButton(Translation.get("gb.subscribe") + "...");
    subscribeRepository.setEnabled(false);
    subscribeRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            List<FeedModel> feeds = gitblit.getAvailableFeeds(getSelectedRepositories().get(0));
            subscribeFeeds(feeds);
        }
    });
    final JButton logRepository = new JButton(Translation.get("gb.log") + "...");
    logRepository.setEnabled(false);
    logRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            RepositoryModel model = getSelectedRepositories().get(0);
            showSearchDialog(false, model);
        }
    });
    final JButton searchRepository = new JButton(Translation.get("gb.search") + "...");
    searchRepository.setEnabled(false);
    searchRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            RepositoryModel model = getSelectedRepositories().get(0);
            showSearchDialog(true, model);
        }
    });
    SubscribedRepositoryRenderer nameRenderer = new SubscribedRepositoryRenderer(gitblit);
    IndicatorsRenderer typeRenderer = new IndicatorsRenderer();
    DefaultTableCellRenderer sizeRenderer = new DefaultTableCellRenderer();
    sizeRenderer.setHorizontalAlignment(SwingConstants.RIGHT);
    sizeRenderer.setForeground(new Color(0, 0x80, 0));
    DefaultTableCellRenderer ownerRenderer = new DefaultTableCellRenderer();
    ownerRenderer.setForeground(Color.gray);
    ownerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
    tableModel = new RepositoriesTableModel();
    defaultSorter = new TableRowSorter<RepositoriesTableModel>(tableModel);
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    table.setRowSorter(defaultSorter);
    table.getRowSorter().toggleSortOrder(RepositoriesTableModel.Columns.Name.ordinal());
    setRepositoryRenderer(RepositoriesTableModel.Columns.Name, nameRenderer, -1);
    setRepositoryRenderer(RepositoriesTableModel.Columns.Indicators, typeRenderer, 100);
    setRepositoryRenderer(RepositoriesTableModel.Columns.Owner, ownerRenderer, -1);
    setRepositoryRenderer(RepositoriesTableModel.Columns.Size, sizeRenderer, 60);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            boolean singleSelection = table.getSelectedRowCount() == 1;
            boolean selected = table.getSelectedRow() > -1;
            if (singleSelection) {
                RepositoryModel repository = getSelectedRepositories().get(0);
                browseRepository.setEnabled(repository.hasCommits);
                logRepository.setEnabled(repository.hasCommits);
                searchRepository.setEnabled(repository.hasCommits);
                subscribeRepository.setEnabled(repository.hasCommits);
            } else {
                browseRepository.setEnabled(false);
                logRepository.setEnabled(false);
                searchRepository.setEnabled(false);
                subscribeRepository.setEnabled(false);
            }
            delRepository.setEnabled(selected);
            if (selected) {
                int viewRow = table.getSelectedRow();
                int modelRow = table.convertRowIndexToModel(viewRow);
                RepositoryModel model = ((RepositoriesTableModel) table.getModel()).list.get(modelRow);
                editRepository.setEnabled(singleSelection && (gitblit.allowManagement() || gitblit.isOwner(model)));
            } else {
                editRepository.setEnabled(false);
            }
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && gitblit.allowManagement()) {
                editRepository(getSelectedRepositories().get(0));
            }
        }
    });
    filterTextfield = new JTextField();
    filterTextfield.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterRepositories(filterTextfield.getText());
        }
    });
    filterTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            filterRepositories(filterTextfield.getText());
        }
    });
    JPanel repositoryFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    repositoryFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
    repositoryFilterPanel.add(filterTextfield, BorderLayout.CENTER);
    JPanel repositoryTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    repositoryTablePanel.add(repositoryFilterPanel, BorderLayout.NORTH);
    repositoryTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
    JPanel repositoryControls = new JPanel(new FlowLayout(FlowLayout.CENTER, Utils.MARGIN, 0));
    repositoryControls.add(clearCache);
    repositoryControls.add(refreshRepositories);
    repositoryControls.add(browseRepository);
    repositoryControls.add(createRepository);
    repositoryControls.add(editRepository);
    repositoryControls.add(delRepository);
    repositoryControls.add(subscribeRepository);
    repositoryControls.add(logRepository);
    repositoryControls.add(searchRepository);
    setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    header = new HeaderPanel(Translation.get("gb.repositories"), "git-orange-16x16.png");
    add(header, BorderLayout.NORTH);
    add(repositoryTablePanel, BorderLayout.CENTER);
    add(repositoryControls, BorderLayout.SOUTH);
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) RepositoryModel(com.gitblit.models.RepositoryModel) JTextField(javax.swing.JTextField) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) ArrayList(java.util.ArrayList) List(java.util.List) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) Color(java.awt.Color) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener)

Example 84 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project java-swing-tips by aterai.

the class FileListTable method updateUI.

@Override
public void updateUI() {
    // [JDK-6788475]
    // Changing to Nimbus LAF and back doesn't reset look and feel of JTable completely
    // https://bugs.openjdk.java.net/browse/JDK-6788475
    // XXX: set dummy ColorUIResource
    setSelectionForeground(new ColorUIResource(Color.RED));
    setSelectionBackground(new ColorUIResource(Color.RED));
    removeMouseMotionListener(rbl);
    removeMouseListener(rbl);
    setDefaultRenderer(Object.class, null);
    super.updateUI();
    rbl = new RubberBandingListener();
    addMouseMotionListener(rbl);
    addMouseListener(rbl);
    putClientProperty("Table.isFileList", Boolean.TRUE);
    setCellSelectionEnabled(true);
    setIntercellSpacing(new Dimension());
    setShowGrid(false);
    setAutoCreateRowSorter(true);
    setFillsViewportHeight(true);
    TableCellRenderer r = new DefaultTableCellRenderer();
    setDefaultRenderer(Object.class, (table, value, isSelected, hasFocus, row, column) -> r.getTableCellRendererComponent(table, value, false, false, row, column));
    TableColumn col = getColumnModel().getColumn(0);
    col.setCellRenderer(new FileNameRenderer(this));
    col.setPreferredWidth(200);
    col = getColumnModel().getColumn(1);
    col.setPreferredWidth(300);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) ColorUIResource(javax.swing.plaf.ColorUIResource) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 85 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project druid by alibaba.

the class GroupableTableHeaderUI method getHeaderHeight.

public int getHeaderHeight() {
    int height = 0;
    TableColumnModel columnModel = header.getColumnModel();
    for (int column = 0; column < columnModel.getColumnCount(); column++) {
        TableColumn aColumn = columnModel.getColumn(column);
        TableCellRenderer renderer = aColumn.getHeaderRenderer();
        if (renderer == null) {
            renderer = new DefaultTableCellRenderer() {

                private static final long serialVersionUID = 1L;

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    JTableHeader header = table.getTableHeader();
                    if (header != null) {
                        setForeground(header.getForeground());
                        setBackground(header.getBackground());
                        setFont(header.getFont());
                    }
                    setHorizontalAlignment(JLabel.CENTER);
                    setText((value == null) ? "" : value.toString());
                    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
                    return this;
                }
            };
        }
        Component comp = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, column);
        int cHeight = comp.getPreferredSize().height;
        Enumeration<ColumnGroup> enumeration = ((GroupableTableHeader) header).getColumnGroups(aColumn);
        if (enumeration != null) {
            while (enumeration.hasMoreElements()) {
                ColumnGroup cGroup = (ColumnGroup) enumeration.nextElement();
                cHeight += cGroup.getSize(header.getTable()).height;
            }
        }
        height = Math.max(height, cHeight);
    }
    height = Math.max(height, m_height);
    return height;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) TableColumnModel(javax.swing.table.TableColumnModel) JTableHeader(javax.swing.table.JTableHeader) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTable(javax.swing.JTable) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Aggregations

DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)85 JTable (javax.swing.JTable)30 TableColumn (javax.swing.table.TableColumn)27 Component (java.awt.Component)21 JScrollPane (javax.swing.JScrollPane)20 DefaultTableModel (javax.swing.table.DefaultTableModel)17 TableCellRenderer (javax.swing.table.TableCellRenderer)17 JLabel (javax.swing.JLabel)14 MouseEvent (java.awt.event.MouseEvent)12 JComponent (javax.swing.JComponent)12 Dimension (java.awt.Dimension)11 Font (java.awt.Font)11 JTableHeader (javax.swing.table.JTableHeader)11 BorderLayout (java.awt.BorderLayout)9 Color (java.awt.Color)9 GridBagConstraints (java.awt.GridBagConstraints)9 Insets (java.awt.Insets)9 JPanel (javax.swing.JPanel)9 GridBagLayout (java.awt.GridBagLayout)7 Point (java.awt.Point)7