Java Code Examples for org.jdesktop.swingx.JXTable#setHighlighters()

The following examples show how to use org.jdesktop.swingx.JXTable#setHighlighters() . 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: Example_7a_View.java    From Java_MVVM_with_Swing_and_RxJava_Examples with Apache License 2.0 5 votes vote down vote up
public Example_7a_View() {
    super();
    setTitle(getClass().getSimpleName() + " " + ManagementFactory.getRuntimeMXBean().getName());

    setBounds(100, 100, 700, 500);
    setDefaultCloseOperation(StrictThreadingJFrame.EXIT_ON_CLOSE);
    getContentPane().setLayout(new BorderLayout(0, 0));

    final JXTable table = new JXTable(myTableModel);
    table.setHighlighters(HighlighterFactory.createSimpleStriping());
    table.setSortable(false);
    table.getTableHeader().setReorderingAllowed(false);

    myTableModel.addTableModelListener(new TableModelListener() {

        int lastRowCountScrolledTo = -1;

        @Override
        public void tableChanged(final TableModelEvent e) {
            if (TableUtilities.isInsert(e)) {
                final int currentRowCount = myTableModel.getRowCount();
                if (currentRowCount != lastRowCountScrolledTo) {
                    lastRowCountScrolledTo = currentRowCount;
                    SwingUtilities.invokeLater(() -> table.scrollRectToVisible(table.getCellRect(myTableModel.getRowCount() - 1, 0, false)));
                }
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(table);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
}
 
Example 2
Source File: Example_7_View.java    From Java_MVVM_with_Swing_and_RxJava_Examples with Apache License 2.0 5 votes vote down vote up
public Example_7_View() {
    super();
    setTitle(getClass().getSimpleName() + " " + ManagementFactory.getRuntimeMXBean().getName());

    setBounds(100, 100, 700, 500);
    setDefaultCloseOperation(StrictThreadingJFrame.EXIT_ON_CLOSE);
    getContentPane().setLayout(new BorderLayout(0, 0));

    final JXTable table = new JXTable(myTableModel);
    table.setHighlighters(HighlighterFactory.createSimpleStriping());
    table.setSortable(false);
    table.getTableHeader().setReorderingAllowed(false);

    myTableModel.addTableModelListener(new TableModelListener() {

        int lastRowCountScrolledTo = -1;

        @Override
        public void tableChanged(final TableModelEvent e) {
            if (TableUtilities.isInsert(e)) {
                final int currentRowCount = myTableModel.getRowCount();
                if (currentRowCount != lastRowCountScrolledTo) {
                    lastRowCountScrolledTo = currentRowCount;
                    SwingUtilities.invokeLater(() -> table.scrollRectToVisible(table.getCellRect(myTableModel.getRowCount() - 1, 0, false)));
                }
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(table);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
}
 
Example 3
Source File: Example_8_View.java    From Java_MVVM_with_Swing_and_RxJava_Examples with Apache License 2.0 5 votes vote down vote up
public Example_8_View() {
    super();
    setTitle(getClass().getSimpleName() + " " + ManagementFactory.getRuntimeMXBean().getName());

    setBounds(100, 100, 700, 500);
    setDefaultCloseOperation(StrictThreadingJFrame.EXIT_ON_CLOSE);
    getContentPane().setLayout(new BorderLayout(0, 0));

    final JXTable table = new JXTable(myTableModel);
    table.setHighlighters(HighlighterFactory.createSimpleStriping());
    table.setSortable(false);
    table.getTableHeader().setReorderingAllowed(false);

    myTableModel.addTableModelListener(new TableModelListener() {

        int lastRowCountScrolledTo = -1;

        @Override
        public void tableChanged(final TableModelEvent e) {
            if (TableUtilities.isInsert(e)) {
                final int currentRowCount = myTableModel.getRowCount();
                if (currentRowCount != lastRowCountScrolledTo) {
                    lastRowCountScrolledTo = currentRowCount;
                    SwingUtilities.invokeLater(() -> table.scrollRectToVisible(table.getCellRect(myTableModel.getRowCount() - 1, 0, false)));
                }
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(table);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
}
 
Example 4
Source File: DesignerTablePanel.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
private void createTable() {
        // create the table
        model = new MyTableModel();
        table = new JXTable(model) {

            private Map<Integer, ComboBoxEditor> editors = new HashMap<Integer, ComboBoxEditor>();

            public boolean getScrollableTracksViewportHeight() {
                return getPreferredSize().height < getParent().getHeight();
            }

            public void changeSelection(int rowIndex, int columnIndex,
                                        boolean toggle, boolean extend) {
                if (!dndRecognizer.isDragged()) {
                    super.changeSelection(rowIndex, columnIndex, toggle, extend);
                }
            }

            public TableCellEditor getCellEditor(int row, int column) {
                if (column != 6) {
                    return super.getCellEditor(row, column);
                }
                ComboBoxEditor editor = editors.get(row);
                if (editor == null) {
                    editor = new ComboBoxEditor(new String[]{"", GROUP_BY, SUM, AVG, MIN, MAX, COUNT});
                    editors.put(row, editor);
                }
                return editor;
            }
        };
        tableRowHeader = TableUtil.setRowHeader(table);
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        TableColumn col = table.getColumnModel().getColumn(3);
//        col.setCellRenderer(TableCellRenderers.getNewDefaultRenderer(Boolean.class));
        col.setCellRenderer(table.getDefaultRenderer(Boolean.class));
        col.setCellEditor(table.getDefaultEditor(Boolean.class));
        table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
        // no border
        JTextField tf = new JTextField();
        tf.setBorder(BorderFactory.createEmptyBorder());
        table.setDefaultEditor(Object.class, new DefaultCellEditor(tf));

        col = table.getColumnModel().getColumn(4);
//        col.setCellRenderer(TableCellRenderers.getNewDefaultRenderer(Boolean.class));
        JComboBox sortCombo = new JComboBox(new String[]{"", ASC, DESC});
        sortCombo.setBorder(BorderFactory.createEmptyBorder());
        col.setCellEditor(new ComboBoxEditor(sortCombo));

        col = table.getColumnModel().getColumn(5);
        sortOrderCombo = new JComboBox();
        sortOrderCombo.setBorder(BorderFactory.createEmptyBorder());
        col.setCellEditor(new ComboBoxEditor(sortOrderCombo));

        col = table.getColumnModel().getColumn(6);

        table.setSortable(false);
        table.setColumnControlVisible(true);
        table.getTableHeader().setReorderingAllowed(false);
        table.setHorizontalScrollEnabled(true);

        // highlight table
        table.setHighlighters(HighlighterFactory.createAlternateStriping(Color.WHITE, ColorUtil.PANEL_BACKROUND_COLOR));

        table.getTableHeader().setReorderingAllowed(false);
        
        table.setRolloverEnabled(true);
        table.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, null, Color.RED)); 
    }
 
Example 5
Source File: UIUtil.java    From ganttproject with GNU General Public License v3.0 2 votes vote down vote up
public static void setupHighlighters(JXTable table) {
  table.setHighlighters(HighlighterFactory.createAlternateStriping(Color.WHITE, Color.ORANGE.brighter()));

}