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

Table grid not painted for checkbox #311

Closed
voidpointergonebad opened this issue Apr 20, 2021 · 3 comments
Closed

Table grid not painted for checkbox #311

voidpointergonebad opened this issue Apr 20, 2021 · 3 comments
Milestone

Comments

@voidpointergonebad
Copy link

voidpointergonebad commented Apr 20, 2021

flatlaf-1.1.2.jar

Bottom dialog without FlatLightLaf.install();

flatlaf

package com.example;

import com.formdev.flatlaf.FlatLightLaf;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;

public final class Test extends JFrame {
  private static final long serialVersionUID = 1L;

  static final String[] COLUMNS = new String[] { "string", "boolean", "string" };
  static final Object[][] DATA = new Object[][] { { "aaa", false, "bbb" }, { "ccc", true, "ddd" }, { "eee", false, "fff" } };
  static final Class<?>[] COLUMN_CLASS = new Class<?>[] { String.class, Boolean.class, String.class };
  static final DefaultTableModel model = new DefaultTableModel(DATA, COLUMNS) {
    @Override
    public boolean isCellEditable(int row, int column) { return false; }
    @Override
    public Class<?> getColumnClass(int columnIndex) { return COLUMN_CLASS[columnIndex]; }
  };

  public Test() {
    final JTable table = new JTable(model);
    table.setShowGrid(true);
    table.setGridColor(Color.LIGHT_GRAY);
    add(new JScrollPane(table));
    setTitle("Test");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setVisible(true);
  }

  public static void main(String[] args) {
    try {
      FlatLightLaf.install();
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() { new Test(); }
      });
    } catch(final Exception e) {}
  }
}
@DevCharly
Copy link
Collaborator

The problem is that the background of the checkbox is filled and paints over the grid lines
because the intercell spacing is 0, 0 in FlatLaf. Other Lafs use intercell spacing 1, 1.

To workaround this, change intercell spacing to 1, 1:

table.setIntercellSpacing( new Dimension( 1, 1 ) );

image

Intercell spacing is zero in FlatLaf because grid lines are hidden by default in FlatLaf.

Intercell spacing affects selection painting:

image

With zero intercell spacing:

image

I work on a solution for the checkboxes that will work also with zero intercell spacing.

@voidpointergonebad
Copy link
Author

The workaround solves the immediate issue - thanks!

DevCharly added a commit that referenced this issue Apr 22, 2021
…erer, except if cell is selected or has different background color (issue #311)
@DevCharly
Copy link
Collaborator

Fixed in main branch. Now works also with zero intercell spacing.

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

2 participants