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

Wrong rollover color for buttons with a background color property #21

Closed
lbalazscs opened this issue Oct 23, 2019 · 7 comments
Closed

Comments

@lbalazscs
Copy link

Using 0.16 and FlatDarculaLaf, buttons have a grey color when the mouse is over them, which is OK when there is no background color set for the button, but looks quite strange (sudden large color changes) when there is an explicitly set background color.

Instead the rollover color should be derived from the background color (if there is one), for example using a lighter or darker version of it (or leaving it as it is). java.awt.Color has brighter() and darker() methods for easily deriving such colors at runtime.

import com.formdev.flatlaf.FlatDarculaLaf;

import javax.swing.*;
import java.awt.Color;
import java.awt.FlowLayout;

public class ColoredButtonProblem {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> buildGUI());
    }

    private static void buildGUI() {
        try {
//            UIManager.setLookAndFeel(new javax.swing.plaf.nimbus.NimbusLookAndFeel());
            UIManager.setLookAndFeel(new FlatDarculaLaf());
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

        JFrame f = new JFrame("Test");
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.setLayout(new FlowLayout());

        JButton blueButton = new JButton("Blue");
        blueButton.setBackground(new Color(13, 67, 159));
        f.add(blueButton);

        JButton uncoloredButton = new JButton("No color, no problem");
        f.add(uncoloredButton);

        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }
}
@DevCharly
Copy link
Collaborator

Great idea. This should also reduce the number of colors to configure...

BTW you can disable the rollover effect for buttons:

blueButton.setRolloverEnabled( false );

@lbalazscs
Copy link
Author

In my special case (color selector) it is not optimal if the rollover changes the color, even if it changes only a little, like in Nimbus. On the other hand it's nice to have some rollover effect, otherwise it looks kind of dead. Probably I will end up using some custom JComponent, but at least I found some bugs for you :)

JFormDesigner pushed a commit that referenced this issue Oct 27, 2019
@JFormDesigner
Copy link
Owner

fixed in 0.17

@JFormDesigner
Copy link
Owner

reopened because the derived hover background color for the blue button in the above test case is hardly to recognize

@JFormDesigner JFormDesigner reopened this Oct 27, 2019
@lbalazscs
Copy link
Author

Looks OK to me, but you know...

In the code I chose that shade of blue, and not simply Color.BLUE because I found that with the pure blue the color change can't be seen even with Nimbus (although there is some other change in the border - maybe you could also do something with the border, as you already do in the case of uncolored buttons). I thought that pure blue must be a rare special case. With pure blue I also don't see a color change with FlatDarculaLaf, but hey, it is enough if it is as good in this regard as Nimbus... :)

In general I think that this should be a subtle, "subconscious" effect, just to get a feeling that something changed. Probably it also depends on monitor configuration whether two colors can be distinguished or not.

@lbalazscs
Copy link
Author

In the meantime I realized that there is a rollover change in the borders, I didn't see it yesterday because it just happens to be a similar color to the blue of the background. So this is already perfect as far as I am concerned.

@DevCharly
Copy link
Collaborator

Thanks @lbalazscs

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