-
-
Notifications
You must be signed in to change notification settings - Fork 268
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
Non opaque ToolBar buttons are opaque when not rolled over #191
Comments
package test.flatlaf;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import com.formdev.flatlaf.FlatLightLaf;
public class ToolBarButtonOpacityTest {
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(new FlatLightLaf());
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel centerPane = new JPanel(new FlowLayout());
centerPane.setBackground(Color.DARK_GRAY);
JToolBar toolBar = new JToolBar();
toolBar.setBorder(BorderFactory.createEmptyBorder());
toolBar.setOpaque(false);
toolBar.setFloatable(false);
toolBar.setRollover(true);
JButton nonOpaqueButton = new JButton("Not opaque");
nonOpaqueButton.setOpaque(false);
nonOpaqueButton.setBackground(Color.RED);
nonOpaqueButton.setFocusable(false);
toolBar.add(nonOpaqueButton);
JButton opaqueButton = new JButton("Opaque");
opaqueButton.setFocusable(false);
opaqueButton.setBackground(Color.RED);
toolBar.add(opaqueButton);
centerPane.add(toolBar);
frame.getContentPane().add(centerPane);
frame.setSize(400, 300);
frame.setVisible(true);
}
} As a workaround, you could try setting the toolbar background as well: toolBar.setBackground(null); // inherit from parent |
I've just found the following https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6687960:
So In this case one wants fully transparent background of the not rolled over button state which appears controlled by FlatLaf, however. |
So, setting the toolBar.setBackground(new Color(0, 0, 0, 0)); This casuses toolbar buttons to inherit the fully transparent color (when not rolled over). |
…ackground color. If no background color is set, then the button background is not painted anymore (issue #191)
Have improved toolbar button background painting in commit b49a498. This changes following:
This is the same behavior as in Nimbus, Substance and Windows Laf (with opaque set to false on buttons). Buttons in FlatLaf are non-opaque by default, which is necessary for round edges and for wide focus-indicator borders (in IntelliJ and Darcula themes). So, to get the desired behavior in |
I don't know if this is a bug or a free choice from look and feel implementers. But we rely on a nice aspect of the Windows L&F, which is that a non opaque button in a toolbar is not opaque when the mouse is not over it. This allows the button to blend to custom toolbars.
Here is a test case and an actual use of this capability, both in Windows and in FlatLaf:
You can also see that the background color is not respected either (but this is not a problem for us).
And here is the source of the test case:
ToolBarButtonOpacityTest.zip
Is there a way to achieve the desired result with toolbar buttons? Do you think this opacity behavior could be implemented in FlatLaf?
The text was updated successfully, but these errors were encountered: