Example usage for java.awt Color Color

List of usage examples for java.awt Color Color

Introduction

In this page you can find the example usage for java.awt Color Color.

Prototype

public Color(ColorSpace cspace, float[] components, float alpha) 

Source Link

Document

Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha.

Usage

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();/*from w w w  .j  a va  2 s .c o  m*/
    PdfContentByte cb = writer.getDirectContent();
    PdfSpotColor psc_g = new PdfSpotColor("iTextSpotColorGray", 0.5f, new GrayColor(0.9f));
    PdfSpotColor psc_rgb = new PdfSpotColor("iTextSpotColorRGB", 0.9f, new Color(0x64, 0x95, 0xed));
    PdfSpotColor psc_cmyk = new PdfSpotColor("iTextSpotColorCMYK", 0.25f, new CMYKColor(0.3f, .9f, .3f, .1f));

    SpotColor sc_g = new SpotColor(psc_g);
    SpotColor sc_rgb1 = new SpotColor(psc_rgb, 0.1f);

    SpotColor sc_cmyk = new SpotColor(psc_cmyk);

    cb.setColorFill(sc_g);
    cb.rectangle(36, 770, 36, 36);
    cb.fillStroke();
    cb.setColorFill(psc_g, psc_g.getTint());
    cb.rectangle(90, 770, 36, 36);
    cb.fillStroke();
    cb.setColorFill(psc_g, 1);
    cb.rectangle(252, 770, 36, 36);
    cb.fillStroke();

    cb.setColorFill(sc_rgb1);
    cb.rectangle(36, 716, 36, 36);
    cb.fillStroke();

    cb.setColorFill(psc_rgb, 0.9f);
    cb.rectangle(36, 662, 36, 36);
    cb.fillStroke();

    cb.setColorFill(sc_cmyk);
    cb.rectangle(36, 608, 36, 36);
    cb.fillStroke();
    cb.setColorFill(psc_cmyk, psc_cmyk.getTint());
    cb.rectangle(90, 608, 36, 36);
    cb.fillStroke();
    document.close();
}

From source file:SubSupScriptPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from   w w w. ja  v a  2 s.co  m
        PdfWriter.getInstance(document, new FileOutputStream("SubSupScriptPDF.pdf"));
        document.open();
        String s = "Text Text Text Text Text Text Text Text Text Text Text Text Text Text ";
        StringTokenizer st = new StringTokenizer(s, " ");
        float textrise = 6.0f;
        Chunk c;
        while (st.hasMoreTokens()) {
            c = new Chunk(st.nextToken());
            c.setTextRise(textrise);
            c.setUnderline(new Color(0xC0, 0xC0, 0xC0), 0.2f, 0.0f, 0.0f, 0.0f, PdfContentByte.LINE_CAP_BUTT);
            document.add(c);
            textrise -= 2.0f;
        }
    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:ChapterSectionNewSectionPagePDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {/*from   w w  w  .ja  v  a  2 s  . c o  m*/
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("ChapterSectionNewSectionPagePDF.pdf"));
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        document.open();
        Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 24, Font.NORMAL, new Color(255, 0, 0));
        Font sectionFont = FontFactory.getFont(FontFactory.HELVETICA, 20, Font.NORMAL, new Color(0, 0, 255));
        Font subsectionFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, new Color(0, 64, 64));

        Paragraph paragraph1 = new Paragraph("text 1");
        Paragraph paragraph2 = new Paragraph("text 2");

        Paragraph cTitle = new Paragraph("This is a chapter ", chapterFont);
        Chapter chapter = new Chapter(cTitle, 1);

        paragraph2.setAlignment(Element.ALIGN_JUSTIFIED);
        paragraph1.setAlignment(Element.ALIGN_JUSTIFIED);
        chapter.add(paragraph1);

        Paragraph sTitle = new Paragraph("This is section 1 in chapter 1", sectionFont);
        Section section = chapter.addSection(sTitle, 1);
        section.add(paragraph1);
        section.add(Chunk.NEXTPAGE);

        Paragraph subTitle = new Paragraph("This is subsection 1 of section 1", subsectionFont);
        Section subsection = section.addSection(subTitle, 3);

        document.add(chapter);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:ChapterSectionSetBookmarkOpenPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {/*  w w w .  java2s  .c o  m*/
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("ChapterSectionSetBookmarkOpenPDF.pdf"));
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        document.open();
        Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 24, Font.NORMAL, new Color(255, 0, 0));
        Font sectionFont = FontFactory.getFont(FontFactory.HELVETICA, 20, Font.NORMAL, new Color(0, 0, 255));
        Font subsectionFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, new Color(0, 64, 64));

        Paragraph paragraph1 = new Paragraph("text 1");
        Paragraph paragraph2 = new Paragraph("text 2");

        Paragraph cTitle = new Paragraph("This is a chapter ", chapterFont);
        Chapter chapter = new Chapter(cTitle, 1);

        paragraph2.setAlignment(Element.ALIGN_JUSTIFIED);
        paragraph1.setAlignment(Element.ALIGN_JUSTIFIED);
        chapter.add(paragraph1);

        Paragraph sTitle = new Paragraph("This is section 1 in chapter 1", sectionFont);
        Section section = chapter.addSection(sTitle, 1);
        section.add(paragraph1);
        section.setBookmarkOpen(false);

        Paragraph subTitle = new Paragraph("This is subsection 1 of section 1", subsectionFont);
        Section subsection = section.addSection(subTitle, 3);

        document.add(chapter);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:AHrefForAWebsitePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from  ww  w. ja  va2  s.  c  om*/
        PdfWriter.getInstance(document, new FileOutputStream("AHrefForAWebsitePDF.pdf"));
        HtmlWriter.getInstance(document, new FileOutputStream("AHrefForAWebsite.html"));

        document.open();

        Paragraph paragraph = new Paragraph("Please visit my ");
        Anchor anchor1 = new Anchor("website (external reference)",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255)));
        anchor1.setReference("http://www.java2s.com");
        paragraph.add(anchor1);

        document.add(paragraph);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:GenerateTwoPDFAndHTMLRTF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from   w  ww.  j  a  v a 2s . c  om*/
        PdfWriter.getInstance(document, new FileOutputStream("AHrefForAWebsite.pdf"));
        HtmlWriter.getInstance(document, new FileOutputStream("AHrefForAWebsite.html"));
        RtfWriter2.getInstance(document, new FileOutputStream("AHrefForAWebsite.html"));

        document.open();

        Paragraph paragraph = new Paragraph("Please visit my ");
        Anchor anchor1 = new Anchor("website (external reference)",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255)));
        anchor1.setReference("http://www.java2s.com");
        paragraph.add(anchor1);

        document.add(paragraph);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document.compress = false;//from w w  w .ja  v  a2  s .c om
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    cb.setColorStroke(new GrayColor(0.2f));
    cb.setColorFill(new GrayColor(0.9f));
    Rectangle rect = new Rectangle(120, 620, 240, 720);
    rect.setBorder(Rectangle.BOX);
    rect.setBorderWidthTop(15);
    rect.setBorderWidthBottom(12);
    rect.setBorderWidthLeft(52);
    rect.setBorderWidthRight(20);
    rect.setBorderColorTop(new GrayColor(0.2f));
    rect.setBorderColorBottom(new Color(0xFF, 0x00, 0x00));
    rect.setBorderColorLeft(new Color(0xFF, 0xFF, 0x00));
    rect.setBorderColorRight(new Color(0x00, 0x00, 0xFF));
    rect.setBackgroundColor(new GrayColor(0.9f));
    cb.rectangle(rect);
    cb.variableRectangle(rect);
    cb.rectangle(rect);
    rect = new Rectangle(250, 620, 370, 720);
    cb.fillStroke();

    document.close();
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Button Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JButton button1 = new JButton("Select Me");
    final JButton button2 = new JButton("No Select Me");
    final Random random = new Random();

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JButton button = (JButton) actionEvent.getSource();
            int red = random.nextInt(255);
            int green = random.nextInt(255);
            int blue = random.nextInt(255);
            button.setBackground(new Color(red, green, blue));
        }/*from ww w  .j  a va  2 s  . co m*/
    };

    PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            String property = propertyChangeEvent.getPropertyName();
            if ("background".equals(property)) {
                button2.setBackground((Color) propertyChangeEvent.getNewValue());
            }
        }
    };

    button1.addActionListener(actionListener);
    button1.addPropertyChangeListener(propertyChangeListener);
    button2.addActionListener(actionListener);

    frame.add(button1, BorderLayout.NORTH);
    frame.add(button2, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:ShadingPatternPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {// w  w  w . j  a  v  a2  s .  co m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ShadingPatternPDF.pdf"));
        document.open();

        PdfShading shading = PdfShading.simpleAxial(writer, 100, 100, 400, 100, Color.red, Color.cyan);
        PdfShadingPattern shadingPattern = new PdfShadingPattern(shading);

        PdfContentByte cb = writer.getDirectContent();

        cb.setShadingFill(shadingPattern);
        cb.circle(50, 50, 50);
        cb.stroke();

        PdfShading shadingR = PdfShading.simpleRadial(writer, 200, 500, 50, 300, 500, 100,
                new Color(255, 247, 148), new Color(247, 138, 107), false, false);
        cb.paintShading(shadingR);

        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:OutlineWithStylePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from  w  w w .  j  av a  2 s  . c  o m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("OutlineWithStylePDF.pdf"));
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        document.open();
        document.add(new Paragraph("Outline action example"));

        PdfContentByte cb = writer.getDirectContent();
        PdfOutline root = cb.getRootOutline();
        PdfOutline links = new PdfOutline(root, new PdfAction("http://www.java2s.com"), "Useful links");
        links.setColor(new Color(0xFF, 0x00, 0x00));
        links.setStyle(Font.BOLD);

    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}