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

Problem displaying check box/radio button with right alignment #734

Closed
Ronnau opened this issue Sep 8, 2023 · 2 comments
Closed

Problem displaying check box/radio button with right alignment #734

Ronnau opened this issue Sep 8, 2023 · 2 comments
Milestone

Comments

@Ronnau
Copy link

Ronnau commented Sep 8, 2023

When displaying a check box or radio button, with right alignment, the right end of the component is being cut.
This is not caused by the width of the component, in the example shown, all components created have the same width, both those that are aligned to the left and those that are aligned to the right.
It happens only using FlatLaf (default properties).
The same code running with Windows LaF or Metal LaF does not present the described behavior.

image

In the image above we can see that the right edge of the check box and radio button are not showing, as well as the text of the components created with the text on the right is not displayed completely.

Code

  public static void main(String[] args) throws Exception {
        Font f = new Font("SansSerif", Font.BOLD, 12);
        JFrame fr = new JFrame(TestProgram.class.getName());
        fr.setSize(400, 400);
        fr.setLocationRelativeTo(null);
        fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fr.getContentPane().setLayout(null);

        JRadioButton rb0 = new JRadioButton("normal right-text right-alignment", null, true);
        rb0.setBounds(50, 10, 300, 15);
        rb0.setBorder(null);
        rb0.setVerticalTextPosition(SwingConstants.CENTER);
        rb0.setHorizontalTextPosition(SwingConstants.RIGHT);
        rb0.setHorizontalAlignment(SwingConstants.RIGHT);
        fr.getContentPane().add(rb0);

        JRadioButton rb1 = new JRadioButton("bold right-text right-alignment", null, true);
        rb1.setFont(f);
        rb1.setBounds(50, 30, 300, 15);
        rb1.setBorder(null);
        rb1.setVerticalTextPosition(SwingConstants.CENTER);
        rb1.setHorizontalTextPosition(SwingConstants.RIGHT);
        rb1.setHorizontalAlignment(SwingConstants.RIGHT);
        fr.getContentPane().add(rb1);

        JRadioButton rb2 = new JRadioButton("normal left-text right-alignment", null, true);
        rb2.setBounds(50, 50, 300, 15);
        rb2.setBorder(null);
        rb2.setVerticalTextPosition(SwingConstants.CENTER);
        rb2.setHorizontalTextPosition(SwingConstants.LEFT);
        rb2.setHorizontalAlignment(SwingConstants.RIGHT);
        fr.getContentPane().add(rb2);

        JRadioButton rb3 = new JRadioButton("bold left-text right-alignment", null, true);
        rb3.setFont(f);
        rb3.setBounds(50, 70, 300, 15);
        rb3.setBorder(null);
        rb3.setVerticalTextPosition(SwingConstants.CENTER);
        rb3.setHorizontalTextPosition(SwingConstants.LEFT);
        rb3.setHorizontalAlignment(SwingConstants.RIGHT);
        fr.getContentPane().add(rb3);

        JCheckBox cb0 = new JCheckBox("normal right-text right-alignment", null, true);
        cb0.setBounds(50, 90, 300, 15);
        cb0.setBorder(null);
        cb0.setVerticalTextPosition(SwingConstants.CENTER);
        cb0.setHorizontalTextPosition(SwingConstants.RIGHT);
        cb0.setHorizontalAlignment(SwingConstants.RIGHT);
        fr.getContentPane().add(cb0);

        JCheckBox cb1 = new JCheckBox("bold right-text right-alignment", null, true);
        cb1.setFont(f);
        cb1.setBounds(50, 110, 300, 15);
        cb1.setBorder(null);
        cb1.setVerticalTextPosition(SwingConstants.CENTER);
        cb1.setHorizontalTextPosition(SwingConstants.RIGHT);
        cb1.setHorizontalAlignment(SwingConstants.RIGHT);
        fr.getContentPane().add(cb1);

        JCheckBox cb2 = new JCheckBox("normal left-text right-alignment", null, true);
        cb2.setBounds(50, 130, 300, 15);
        cb2.setBorder(null);
        cb2.setVerticalTextPosition(SwingConstants.CENTER);
        cb2.setHorizontalTextPosition(SwingConstants.LEFT);
        cb2.setHorizontalAlignment(SwingConstants.RIGHT);
        fr.getContentPane().add(cb2);

        JCheckBox cb3 = new JCheckBox("bold left-text right-alignment", null, true);
        cb3.setFont(f);
        cb3.setBounds(50, 150, 300, 15);
        cb3.setBorder(null);
        cb3.setVerticalTextPosition(SwingConstants.CENTER);
        cb3.setHorizontalTextPosition(SwingConstants.LEFT);
        cb3.setHorizontalAlignment(SwingConstants.RIGHT);
        fr.getContentPane().add(cb3);

        JRadioButton rb4 = new JRadioButton("normal right-text left-alignment", null, true);
        rb4.setBounds(50, 170, 300, 15);
        rb4.setBorder(null);
        rb4.setVerticalTextPosition(SwingConstants.CENTER);
        rb4.setHorizontalTextPosition(SwingConstants.RIGHT);
        rb4.setHorizontalAlignment(SwingConstants.LEFT);
        fr.getContentPane().add(rb4);

        JRadioButton rb5 = new JRadioButton("bold right-text left-alignment", null, true);
        rb5.setFont(f);
        rb5.setBounds(50, 190, 300, 15);
        rb5.setBorder(null);
        rb5.setVerticalTextPosition(SwingConstants.CENTER);
        rb5.setHorizontalTextPosition(SwingConstants.RIGHT);
        rb5.setHorizontalAlignment(SwingConstants.LEFT);
        fr.getContentPane().add(rb5);

        JRadioButton rb6 = new JRadioButton("normal left-text left-alignment", null, true);
        rb6.setBounds(50, 210, 300, 15);
        rb6.setBorder(null);
        rb6.setVerticalTextPosition(SwingConstants.CENTER);
        rb6.setHorizontalTextPosition(SwingConstants.LEFT);
        rb6.setHorizontalAlignment(SwingConstants.LEFT);
        fr.getContentPane().add(rb6);

        JRadioButton rb7 = new JRadioButton("bold left-text left-alignment", null, true);
        rb7.setFont(f);
        rb7.setBounds(50, 230, 300, 15);
        rb7.setBorder(null);
        rb7.setVerticalTextPosition(SwingConstants.CENTER);
        rb7.setHorizontalTextPosition(SwingConstants.LEFT);
        rb7.setHorizontalAlignment(SwingConstants.LEFT);
        fr.getContentPane().add(rb7);

        JCheckBox cb4 = new JCheckBox("normal right-text left-alignment", null, true);
        cb4.setBounds(50, 250, 300, 15);
        cb4.setBorder(null);
        cb4.setVerticalTextPosition(SwingConstants.CENTER);
        cb4.setHorizontalTextPosition(SwingConstants.RIGHT);
        cb4.setHorizontalAlignment(SwingConstants.LEFT);
        fr.getContentPane().add(cb4);

        JCheckBox cb5 = new JCheckBox("bold right-text left-alignment", null, true);
        cb5.setFont(f);
        cb5.setBounds(50, 270, 300, 15);
        cb5.setBorder(null);
        cb5.setVerticalTextPosition(SwingConstants.CENTER);
        cb5.setHorizontalTextPosition(SwingConstants.RIGHT);
        cb5.setHorizontalAlignment(SwingConstants.LEFT);
        fr.getContentPane().add(cb5);

        JCheckBox cb6 = new JCheckBox("normal left-text left-alignment", null, true);
        cb6.setBounds(50, 290, 300, 15);
        cb6.setBorder(null);
        cb6.setVerticalTextPosition(SwingConstants.CENTER);
        cb6.setHorizontalTextPosition(SwingConstants.LEFT);
        cb6.setHorizontalAlignment(SwingConstants.LEFT);
        fr.getContentPane().add(cb6);

        JCheckBox cb7 = new JCheckBox("bold left-text left-alignment", null, true);
        cb7.setFont(f);
        cb7.setBounds(50, 310, 300, 15);
        cb7.setBorder(null);
        cb7.setVerticalTextPosition(SwingConstants.CENTER);
        cb7.setHorizontalTextPosition(SwingConstants.LEFT);
        cb7.setHorizontalAlignment(SwingConstants.LEFT);
        fr.getContentPane().add(cb7);

        fr.setVisible(true);
  }
@Ronnau
Copy link
Author

Ronnau commented Sep 8, 2023

Information that may help with this issue:
The border used by default in the check box/radio button is FlatMarginBorder.
When using an alternative border, such as FlatTextBorder, the problem stopped occurring.

DevCharly added a commit that referenced this issue Sep 28, 2023
…oved and horizontal alignment is set to `right` (issue #734)
@DevCharly
Copy link
Collaborator

Thanks for reporting 👍

This issue occurs only if you remove the default border (or use EmptyBorder(0,0,0,0)) and set horizontal alignment to the right.

fixed in latest 3.3-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

@DevCharly DevCharly added this to the 3.3 milestone Sep 28, 2023
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