Skip to content

JTable has inconsistent design between different themes #750

@ghost

Description

Dear Friends,

I've come to realize that the JTable component isn't fully consistent and stable between different themes.

I'm not entirely sure of how I could describe the issue but here's a GIF of what I've been able to recreate:
FlatLafTableIssue-GIF
(Please ignore the low quality of the GIF)

I'm not allowed to show the production code here but this is the single-method example that I used for the GIF:

public final class FlatLafTableIssue {
	
	public static void main(final String... args) {
		{
			FlatLightLaf.setup();
			UIManager.put("TitlePane.unifiedBackground", false);
		}
		
		boolean dark[] = new boolean[] { false };
		
		final JFrame frame = new JFrame();
		frame.setSize(680, 400);
		frame.setTitle("FlatLafTableIssue");
		frame.setResizable(false);
		frame.setLocationRelativeTo(null);
		frame.setJMenuBar(new JMenuBar());
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		final JPanel panel = (JPanel) frame.getContentPane();
		panel.setLayout(new BorderLayout());
		
		final JTable table = new JTable();
		table.setModel(new DefaultTableModel(200, 5));
		table.setIntercellSpacing(new Dimension(1, 1));
		table.setShowHorizontalLines(true);
		
		final JPanel tablePanel = new JPanel(new BorderLayout());
		tablePanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 5, 20));
		tablePanel.add(new JScrollPane(table));
		
		final JButton button = new JButton();
		button.setText("Toggle");
		button.addActionListener((event) -> {
			dark[0] = !dark[0];
			FlatAnimatedLafChange.showSnapshot();
			
			FlatLaf.setup(dark[0] ? new FlatDarkLaf() : new FlatLightLaf());
			FlatLaf.updateUI();
			
			FlatAnimatedLafChange.hideSnapshotWithAnimation();
		});
		
		final JPanel buttonPanel = new JPanel(new BorderLayout());
		buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 20, 20, 20));
		buttonPanel.add(button);
		
		panel.add(tablePanel);
		panel.add(buttonPanel, BorderLayout.SOUTH);
		
		frame.setVisible(true);
		
	}
	
}

I used FlatLaf-3.2.1 and FlatLaf-Extras-3.2.1 as well, but the Issue is also replicable without the usage of the FlatAnimatedLafChange class that is provided by the FlatLaf-Extras module, I only used it for the smooth switching between themes. I also tried out the same example with the FlatTable component provided by FlatLaf-Extras but nothing changed. Everything has been compiled using Java 21.

Here's a ZIP archive that contains the .jar file used for the example (If you don't want to compile it yourself):
FlatLaf-3.2.1-Table-Issue.zip

You can run the .jar it with

java -jar FlatLaf-3.2.1-Table-Issue.jar

or just by double clicking the file (If you have Java installed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions