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

Clipping doesn't work on JPanel after setXORMode method call.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: 6u30
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version " 1.6.0.30 "
      Java<TM> SE Runtime Environment (build 1.6.0_30-b12)
      Java HotSpot(TM) Client VM (build 20.5-b03, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      On JPanel, clipping doesn't work after when I call setXORMode method like below code.

          g2.setXORMode(Color.white);

      After this I drew rectangle but it wasn't clipped as i did.

      I think JPanel can't handle these kind of thing. it's ok. when i using awt .



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.geom.Area;
      import java.awt.geom.RoundRectangle2D;

      import javax.swing.*;
      import javax.swing.event.*;

      ///////////////////////////////////////////////////// DemoDrawing2
      public class DemoDrawing2 extends JFrame {

          //===================================================== fields
          private DrawingArea left = new DrawingArea();
          

          //================================================ Constructor
          public DemoDrawing2() {
              left.setBackground(Color.white);
              
              JButton changeColorBtn = new JButton( " Randomize Colors " );
              changeColorBtn.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                          left.setMyColor(randomColor());
                      }
                  });

              //... Add components to layout
              JPanel content = new JPanel();
              content.setLayout(new BorderLayout(5, 5));
              content.add(changeColorBtn, BorderLayout.NORTH);
              content.add(left, BorderLayout.CENTER);
              
              //... Set window characteristics
              setContentPane(content);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setTitle( " Demo Drawing " );
              setLocationRelativeTo(null); // Center window.
              pack();
          }


          //=================================================== randomColor
          private static Color randomColor() {
              return new Color((int) (Math.random() * 256), // Red
                               (int) (Math.random() * 256), // Green
                               (int) (Math.random() * 256)); // Blue
          }


          //========================================================== main
          public static void main(String[] args) {
              JFrame window = new DemoDrawing2();
              window.setVisible(true);
          }
      }

      ///////////////////////////////////////////////////////// DrawingArea
      class DrawingArea extends JPanel {

      //======================================================== fields
      private Color _ovalColor; // Color of oval.

      //=================================================== constructor
      public DrawingArea() {
      _ovalColor = Color.GREEN; // Initial color.
      setPreferredSize(new Dimension(100,100));
      }

      //================================================ paintComponent
      @Override public void paintComponent(Graphics g) {
      super.paintComponent(g); // Ask parent to paint background.

      Graphics2D g2 = (Graphics2D)g;
      g2.setColor(_ovalColor);
      int w = getWidth(); // Size might have changed if
      int h = getHeight(); // user resized window.
      Area areaRoundRect = new Area(new RoundRectangle2D.Double(0, 0, w, h, 70.0f, 70.0f));
      g2.clip(areaRoundRect);
      g2.setXORMode(Color.white);
      g2.fillRect(0, 0, w, h);
      }

      //==================================================== setMyColor
      public void setMyColor(Color col) {
      _ovalColor = col; // Remember color.
      repaint(); // Color changed, must repaint
      }
      }

      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: