Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customization of table in flatlaf #780

Closed
VKaddala opened this issue Dec 15, 2023 · 4 comments
Closed

Customization of table in flatlaf #780

VKaddala opened this issue Dec 15, 2023 · 4 comments
Milestone

Comments

@VKaddala
Copy link

I am adding table customization to my application using flatlaf. I want to achieve something like the following:

image

But after doing all property changes, I end up to the below extension:

image

Can you please help me to achieve required UI change.

@VKaddala
Copy link
Author

Can anyone help on this please.

@DJ-Raven
Copy link
Contributor

My solution is custom table cell render. I not sure the flatlaf have the properties style

table.setShowVerticalLines(true);
applyStye(table, 0);
private void applyStye(JTable table, int colIndex) {
    final TableCellRenderer oldCellRender = table.getDefaultRenderer(Boolean.class);
    table.getColumnModel().getColumn(colIndex).setCellRenderer(new DefaultTableCellRenderer() {
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component com = oldCellRender.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (isSelected) {
                com.setBackground(UIManager.getColor("Table.selectionBackground"));
            } else {
                if (row % 2 != 0) {
                    com.setBackground(UIManager.getColor("Table.alternateRowColor"));
                } else {
                    com.setBackground(UIManager.getColor("Table.background"));
                }
            }
            return com;
        }
    });
}

Here My FlatLaf.properties

Table.alternateRowColor=#F5F5F5

Table.gridColor=#D6D6D6
Table.intercellSpacing=1,1

2023-12-18_164645

@DevCharly
Copy link
Collaborator

The problem is that the boolean renderer (see class JTable.BooleanRenderer) does not support alternating row colors. This is IMHO actually a bug in Swing...

Because that boolean renderer is implemented and set in JTable, I actually thought that it would be a bad idea to replace it in FlatLaf. But now I found out that other L&Fs (Nimbus, Radiance, ...) do replace that boolean renderer. So I'm going to do the same in FlatLaf... 😄

DevCharly added a commit that referenced this issue Dec 21, 2023
@DevCharly
Copy link
Collaborator

fixed in latest 3.3-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

@DevCharly DevCharly added this to the 3.3 milestone Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants