Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6482481

JButton focus rectangle on Windows Vista need offset

XMLWordPrintable

        FULL PRODUCT VERSION :
        java version "1.6.0-rc"
        Java(TM) SE Runtime Environment (build 1.6.0-rc-b102)
        Java HotSpot(TM) Client VM (build 1.6.0-rc-b102, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows Vista RC1

        A DESCRIPTION OF THE PROBLEM :
        The focus rectangle painted around JButton when using Windows LnF onWindows Vista does not match the naitive look.

        In the naitive look the dashed lines that make up the rectangle are offset by one, i.e. they start with a blank pixel then a filled pixel then blank, etc. In the windows lnf this is reversed starting with a filled pixel then a blank pixel then a filled one, etc.

        The result is that the corners of focused buttons appear more crowded.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run SwingSet2.jar on windows vista, select the Button panel and click on one of the buttons to see how the windows lnf renders focus.

        In windows right-click on the desktop and select 'Personalise' click the 'Windows colour and Appearence' link at the top. Press the mouse on the OK button but drag off of it and release so that it retains focus. Press the right arrow button (or TAB) to make the focus rectangle show.

        Compare the two focus rectangles to see the difference.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The dashed rectangle should start with an empty pixel.

        see: http://indomus.co.uk/java/vista-button.png
        ACTUAL -
        Dashed focus rectangle starts with a filled pixel.

        see: http://indomus.co.uk/java/java-button.png

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        package test;

        import java.awt.Component;
        import java.awt.FlowLayout;
        import java.awt.Graphics;

        import javax.swing.JButton;
        import javax.swing.JFrame;
        import javax.swing.JPanel;
        import javax.swing.SwingUtilities;
        import javax.swing.UIManager;
        import javax.swing.UnsupportedLookAndFeelException;

        public class FocusPaint implements Runnable {

        public static void main(String[] args) {
        SwingUtilities.invokeLater(new FocusPaint());
        }

        public void run() {
        try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        e.printStackTrace();
        }

        JFrame frame = new JFrame("Focus Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
        Component wrong = new JButton("Default Button");
        Component right = new JPanel(null) {
        public void paintComponent(Graphics g) {
        super.paintComponent(g);
        drawDashedRect(g, 0, 0, getWidth(), getHeight(), 1);
        }
        };
        right.setPreferredSize(wrong.getPreferredSize());

        p.add(wrong);
        p.add(right);

        frame.add(p);

        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        }

        // draw correct dashed rect
            public static void drawDashedRect(Graphics g,int x,int y,int width,int height, int offset) {
             // extended from javax.swing.plaf.basic.BasicGraphicUtils
                int vx,vy;

                // draw upper and lower horizontal dashes
                for (vx = x + offset; vx < (x + width); vx+=2) {
                    g.fillRect(vx, y, 1, 1);
                    g.fillRect(vx, y + height-1, 1, 1);
                }

                // draw left and right vertical dashes
                for (vy = y + offset; vy < (y + height); vy+=2) {
        g.fillRect(x, vy, 1, 1);
                    g.fillRect(x+width-1, vy, 1, 1);
                }
            }
        }
        ---------- END SOURCE ----------

              peterz Peter Zhelezniakov
              tyao Ting-Yun Ingrid Yao (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: