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

Heavy Popups: correct way to find if popup has borders or not (win10 vs win11) #943

Open
VISTALL opened this issue Dec 15, 2024 · 1 comment

Comments

@VISTALL
Copy link

VISTALL commented Dec 15, 2024

Windows 11 - no borders set to component(and rounded borders enabled)

image

Windows 10/Windows 11 (without round borders)

image

How I can determinate - popup with border or not?

  • check flag com.formdev.flatlaf.ui.FlatPopupFactory#KEY_POPUP_USES_NATIVE_BORDER?
  • Maybe laf - will set default border for popup (default impl always, if there no round bourders)? Without setting it from user code
import com.formdev.flatlaf.FlatLightLaf;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;

/**
 * @author VISTALL
 * @since 2024-12-15
 */
public class BordersCheck {
    public static class MyPopupContent extends JPanel {
        public MyPopupContent() {
            super(new BorderLayout(5, 5));
           // setBorder(new LineBorder(Color.RED, 1));
            JLabel label = new JLabel("Some looooooooooooooooooooooooooooooong Text");
            label.setBorder(new EmptyBorder(5, 5, 5, 5));
            add(label);
        }
    }

    private static Popup ourPopup;

    public static void main(String[] args) {
        FlatLightLaf.setup();

        UIManager.put("Popup.forceHeavyWeight", true);

        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame();
            frame.setSize(500, 200);
            frame.setLocationRelativeTo(null);
            frame.setLocationByPlatform(false);

            JPanel panel = new JPanel();
            frame.add(panel);

            JCheckBox rounded = new JCheckBox("Enabled Rounded Borders");
            rounded.setSelected(true);


            JButton button = new JButton("Show Heavy Popup");
            button.addActionListener(e -> {
                if (ourPopup != null) {
                    ourPopup.hide();
                    ourPopup = null;
                }
                else {
                    Point loc = button.getLocationOnScreen();
                    MyPopupContent content = new MyPopupContent();
                    if (rounded.isSelected()) {
                        content.putClientProperty("Popup.borderCornerRadius", 6);
                    } else {
                        content.putClientProperty("Popup.borderCornerRadius", 0);
                    }
                    ourPopup = PopupFactory.getSharedInstance().getPopup(button, content, loc.x , loc.y + 50);
                    ourPopup.show();

                    System.out.println(content.getClientProperty("FlatLaf.internal.FlatPopupFactory.popupUsesNativeBorder"));
                }
            });

            JPanel container = new JPanel();
            container.add(rounded);
            container.add(button);

            panel.add(container);

            frame.setVisible(true);
        });
    }
}
@VISTALL VISTALL changed the title Heavy Popups: correct way to find has popup border or not (win10 vs win11) Heavy Popups: correct way to find if popup has borders or not (win10 vs win11) Dec 15, 2024
@ringin31
Copy link

how to learn,, github

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