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

Wrong mapping of JLabel etc. foreground color when b/w printing

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • client-libs
    • 2d
    • x86
    • windows_nt, windows_2000



      Name: jk109818 Date: 08/19/2002


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      AND

      java version "1.4.1-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
      Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)


      FULL OPERATING SYSTEM VERSION :
      Windows NT Version 4.0

      A DESCRIPTION OF THE PROBLEM :
      When printing a JLabel (but also JTextField) on a
      black/white (laser) printer the foreground color is not
      mapped as expected (at least: black->black and white->white)
      but (e.g.)
      Color.black -> white
      Color.blue -> black (ok)
      Color.red -> white
      Color.green -> white
      etc.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1.Compile and run the code
      2.Press the Print button printing to a b/w printer
      3.Look at the paper

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The expected mappings, at least black staying black.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.print.*;
      import java.awt.event.ActionListener;
      import java.awt.event.ActionEvent;
      import javax.swing.*;


      public class PrintTest extends JFrame{

      private static Color[] colors= {Color.black, Color.blue,

      Color.red, Color.green,

      Color.white, Color.cyan,

      Color.darkGray, Color.gray,

      Color.lightGray, Color.magenta,
      Color.orange,
      Color.pink,

      Color.yellow};

      public PrintTest(){
      final JPanel panel= new JPanel(new GridLayout(0, 1));
      final Printable printable= new Printable() {
      public int print(Graphics g, PageFormat
      pageFormat, int pageIndex) {
      if (pageIndex != 0)
      return NO_SUCH_PAGE;

      double pageHeight =
      pageFormat.getImageableHeight();
      double pageWidth =
      pageFormat.getImageableWidth();

      int w= panel.getWidth(), h=
      panel.getHeight();

      Graphics2D g2 = (Graphics2D)g;
      g2.translate(pageFormat.getImageableX(),
      pageFormat.getImageableY());
      g2.setClip(0, 0, (int)(w), (int)(h));
      panel.paint(g2);
      return PAGE_EXISTS;
      }
      };
      for (int i=0; i<colors.length; i++) {
      Color color= colors[i];
      JLabel label= new JLabel(color.toString());
      label.setForeground(color);
      panel.add(label);
      }
      getContentPane().add(panel, BorderLayout.CENTER);
      JButton button= new JButton("Print");
      getContentPane().add(button, BorderLayout.SOUTH);
      button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      PrinterJob
      pj=PrinterJob.getPrinterJob();
      pj.setPrintable(printable);
      if (pj.printDialog()) {
      try {
      pj.print();
      } catch (PrinterException e1) {
      }
      }
      }
      });
      pack();
      }

      public static void main(String[] args) {
      (new PrintTest()).show();
      }

      }

      ---------- END SOURCE ----------
      (Review ID: 163340)
      ======================================================================

            jgodinez Jennifer Godinez (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: