FlatLaf
FlatLaf copied to clipboard
Heavy Popups: correct way to find if popup has borders or not (win10 vs win11)
Windows 11 - no borders set to component(and rounded borders enabled)
Windows 10/Windows 11 (without round borders)
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);
});
}
}
how to learn,, github