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 header background is never restored after hover when the renderer background is null #790

Merged
merged 2 commits into from Jan 10, 2024

Conversation

dar-dev
Copy link
Contributor

@dar-dev dar-dev commented Jan 9, 2024

The table header background is never restored after hover when the label renderer is opaque.

Here's a demo video:

tableheader_hover.mp4

Cheers,

Dar

--

The table header background is never restored after hover when the label renderer is opaque
@DevCharly
Copy link
Collaborator

... when the label renderer is opaque.

Sorry, but I'm not sure what you mean.
Is the renderer's background color null?

Could you please extend following test case to demonstrate the issue? Thanks.

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import com.formdev.flatlaf.FlatLightLaf;

public class TableHeaderTest
{
	public static void main( String[] args ) {
		SwingUtilities.invokeLater( () -> {
			FlatLightLaf.setup();

			JTable table = new JTable( new DefaultTableModel( 3, 3 ) );
			JScrollPane scrollPane = new JScrollPane( table );

			JFrame frame = new JFrame( "Test" );
			frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
			frame.add( scrollPane );

			frame.setSize( 400, 300 );
			frame.setVisible( true );
		} );
	}
}

@dar-dev
Copy link
Contributor Author

dar-dev commented Jan 10, 2024

Yep sorry, I made a mistake in the report. The case is when the label renderer has null background.

Here's the test case to replicate:

import java.awt.*;

import javax.swing.*;
import javax.swing.table.*;

import com.formdev.flatlaf.*;

public class TableHeaderTest
{
	public static void main( String[] args ) {
		SwingUtilities.invokeLater( () -> {
			FlatLightLaf.setup();

			JTable table = new JTable( new DefaultTableModel( 3, 3 ) );
			JScrollPane scrollPane = new JScrollPane( table );

			// install custom renderer
			final Icon[] icons = { UIManager.getIcon("FileChooser.newFolderIcon"), UIManager.getIcon("FileChooser.upFolderIcon"), UIManager.getIcon("FileChooser.homeFolderIcon") };
			table.getTableHeader().setDefaultRenderer( new DefaultTableCellRenderer() {
				public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
					setIcon(icons[column]);
					return this;
				}
			} );
			
			JFrame frame = new JFrame( "Test" );
			frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
			frame.add( scrollPane );

			frame.setSize( 400, 300 );
			frame.setVisible( true );
		} );
	}
}

@dar-dev dar-dev changed the title Table header background is never restored after hover when using opaque renderer Table header background is never restored after hover when the renderer background is null Jan 10, 2024
@DevCharly
Copy link
Collaborator

Thanks, now I understand 😄

Background and foreground colors are set to null in DefaultTableCellRenderer.updateUI().
DefaultTableCellRenderer.getTableCellRendererComponent() would change those colors to non-null values,
but this method is overridden. So they stay null and FlatLaf does not restore them...

@DevCharly DevCharly merged commit 6fdc56f into JFormDesigner:main Jan 10, 2024
@DevCharly DevCharly added this to the 3.3 milestone Jan 10, 2024
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

Successfully merging this pull request may close these issues.

None yet

2 participants