Example usage for java.awt Color BLACK

List of usage examples for java.awt Color BLACK

Introduction

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

Prototype

Color BLACK

To view the source code for java.awt Color BLACK.

Click Source Link

Document

The color black.

Usage

From source file:MainClass.java

public static void main(String[] a) {
    final int STRING_POSITION = 1;
    Object buttonColors[][] = { { Color.RED, "RED" }, { Color.BLUE, "BLUE" }, { Color.GREEN, "GREEN" },
            { Color.BLACK, "BLACK" }, null, // separator
            { Color.CYAN, "CYAN" } };

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ActionListener actionListener = new TheActionListener();

    JToolBar toolbar = new JToolBar();
    toolbar.setRollover(true);/*from   w w w .j ava2s .  c  o  m*/

    for (Object[] color : buttonColors) {
        if (color == null) {
            toolbar.addSeparator();
        } else {
            Icon icon = MetalIconFactory.getTreeComputerIcon();
            JButton button = new JButton(icon);
            button.setActionCommand((String) color[STRING_POSITION]);
            button.addActionListener(actionListener);
            toolbar.add(button);
        }
    }

    Action action = new ShowAction(toolbar);
    JButton button = new JButton(action);
    toolbar.add(button);

    Container contentPane = frame.getContentPane();
    contentPane.add(toolbar, BorderLayout.NORTH);
    JTextArea textArea = new JTextArea();
    JScrollPane pane = new JScrollPane(textArea);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(350, 150);
    frame.setVisible(true);

}

From source file:TextFieldsPDF.java

License:asdf

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate());
    try {/*from   w  w  w.j a va  2 s  . co m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TextFieldsPDF.pdf"));
        document.open();

        TextField tf = new TextField(writer, new Rectangle(100, 300, 100 + 100, 300 + 50), "asdf");
        tf.setBackgroundColor(Color.WHITE);
        tf.setBorderColor(Color.BLACK);
        tf.setBorderWidth(1);
        tf.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
        tf.setText("text...");
        tf.setAlignment(Element.ALIGN_CENTER);
        tf.setOptions(TextField.MULTILINE | TextField.REQUIRED);
        tf.setRotation(90);
        PdfFormField field = tf.getTextField();
        writer.addAnnotation(field);

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

From source file:TransparencyPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {/*from ww w . j ava 2 s  . c o m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TransparencyPDF.pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();

        PdfGState gs1 = new PdfGState();
        gs1.setFillOpacity(0.5f);

        cb.setGState(gs1);

        cb.setColorStroke(Color.black);
        cb.setColorFill(Color.gray);
        cb.rectangle(0, 0, 100, 200);
        cb.fill();
        cb.setLineWidth(2);
        cb.rectangle(0, 0, 200, 200);
        cb.stroke();

        PdfGState gs2 = new PdfGState();
        gs2.setFillOpacity(0.1f);

        cb.setGState(gs2);

        cb.setColorStroke(Color.black);
        cb.setColorFill(Color.gray);
        cb.rectangle(50, 50, 100, 200);
        cb.fill();
        cb.setLineWidth(2);
        cb.rectangle(50, 50, 200, 200);
        cb.stroke();

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

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  ww w  .  j  ava  2 s  .  c om

    PdfContentByte cb = writer.getDirectContent();
    BarcodeEAN codeEAN = new BarcodeEAN();
    codeEAN.setCode("4512345678906");
    Paragraph p = new Paragraph();

    // it is composed of 3 blocks whith AI 01, 3101 and 10
    Barcode128 uccEan128 = new Barcode128();
    uccEan128.setCodeType(Barcode.CODE128_UCC);
    uccEan128.setCode("(01)00000090311314(10)ABC123(15)060916");
    document.add(uccEan128.createImageWithBarcode(cb, Color.blue, Color.black));

    document.add(p);
    document.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    final BufferedImage trans = getTransparentImage(ImageIO.read(url), Color.BLACK);
    Runnable r = new Runnable() {
        @Override/*w ww  .  j av  a2 s . c om*/
        public void run() {
            JLabel gui = new JLabel(new ImageIcon(trans));
            JOptionPane.showMessageDialog(null, gui);
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:WriteImageType.java

static public void main(String args[]) throws Exception {
    try {/*from  w  ww  .  ja  va 2 s. com*/
        int width = 200, height = 200;

        // TYPE_INT_ARGB specifies the image format: 8-bit RGBA packed
        // into integer pixels
        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D ig2 = bi.createGraphics();

        Font font = new Font("TimesRoman", Font.BOLD, 20);
        ig2.setFont(font);
        String message = "www.java2s.com!";
        FontMetrics fontMetrics = ig2.getFontMetrics();
        int stringWidth = fontMetrics.stringWidth(message);
        int stringHeight = fontMetrics.getAscent();
        ig2.setPaint(Color.black);
        ig2.drawString(message, (width - stringWidth) / 2, height / 2 + stringHeight / 4);

        ImageIO.write(bi, "PNG", new File("c:\\yourImageName.PNG"));
        ImageIO.write(bi, "JPEG", new File("c:\\yourImageName.JPG"));
        ImageIO.write(bi, "gif", new File("c:\\yourImageName.GIF"));
        ImageIO.write(bi, "BMP", new File("c:\\yourImageName.BMP"));

    } catch (IOException ie) {
        ie.printStackTrace();
    }

}

From source file:ComplexRenderingSample.java

public static void main(String args[]) {

    Object elements[][] = {//from  w  w  w  .j  a v a 2s  .  c  om
            { new Font("Helvetica", Font.PLAIN, 20), Color.red, new DiamondIcon(Color.blue), "Help" },
            { new Font("TimesRoman", Font.BOLD, 14), Color.blue, new DiamondIcon(Color.green), "Me" },
            { new Font("Courier", Font.ITALIC, 18), Color.green, new DiamondIcon(Color.black), "I'm" },
            { new Font("Helvetica", Font.BOLD | Font.ITALIC, 12), Color.gray, new DiamondIcon(Color.magenta),
                    "Trapped" },
            { new Font("TimesRoman", Font.PLAIN, 32), Color.pink, new DiamondIcon(Color.yellow), "Inside" },
            { new Font("Courier", Font.BOLD, 16), Color.yellow, new DiamondIcon(Color.red), "This" },
            { new Font("Helvetica", Font.ITALIC, 8), Color.darkGray, new DiamondIcon(Color.pink),
                    "Computer" } };

    JFrame frame = new JFrame("Complex Renderer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    JList jlist = new JList(elements);
    ListCellRenderer renderer = new ComplexCellRenderer();
    jlist.setCellRenderer(renderer);
    JScrollPane scrollPane = new JScrollPane(jlist);
    contentPane.add(scrollPane, BorderLayout.CENTER);

    JComboBox comboBox = new JComboBox(elements);
    comboBox.setRenderer(renderer);
    contentPane.add(comboBox, BorderLayout.NORTH);

    frame.setSize(300, 300);
    frame.setVisible(true);
}

From source file:OverlaySample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Overlay Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel() {
        public boolean isOptimizedDrawingEnabled() {
            return false;
        }/* w  w w .  j a  v  a2 s  .  c  om*/
    };
    LayoutManager overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);

    JButton button = new JButton("Small");
    button.setMaximumSize(new Dimension(25, 25));
    button.setBackground(Color.white);
    panel.add(button);

    button = new JButton("Medium");
    button.setMaximumSize(new Dimension(50, 50));
    button.setBackground(Color.gray);
    panel.add(button);

    button = new JButton("Large");
    button.setMaximumSize(new Dimension(100, 100));
    button.setBackground(Color.black);
    panel.add(button);

    frame.add(panel, BorderLayout.CENTER);

    frame.setSize(400, 300);
    frame.setVisible(true);
}

From source file:MultiColumnRegularColumnsPDF.java

public static void main(String[] args) {
    try {//ww  w . j  a v  a 2s .co m
        Document document = new Document();
        OutputStream out = new FileOutputStream("MultiColumnRegularColumnsPDF.pdf");
        PdfWriter.getInstance(document, out);
        document.open();

        MultiColumnText mct = new MultiColumnText();
        mct.setColumnsRightToLeft(true);
        mct.addRegularColumns(document.left(), document.right(), 10f, 3);

        for (int i = 0; i < 30; i++) {
            mct.addElement(new Paragraph(String.valueOf(i + 1)));
            Paragraph p = new Paragraph("text text text text text text text text text text text ",
                    FontFactory.getFont("Helvetica", 10, Font.NORMAL, Color.BLACK));
            p.setAlignment(Element.ALIGN_LEFT);
            p.setLeading(12f);

            mct.addElement(p);
        }

        document.add(mct);
        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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  ww w . ja  v  a 2 s  . co  m

    PdfContentByte cb = writer.getDirectContent();
    BarcodeEAN codeEAN = new BarcodeEAN();
    codeEAN.setCode("4512345678906");
    Paragraph p = new Paragraph();

    // Data for the barcode :
    Barcode128 shipBarCode = new Barcode128();
    shipBarCode.setX(0.75f);
    shipBarCode.setN(1.5f);
    shipBarCode.setSize(10f);
    shipBarCode.setTextAlignment(Element.ALIGN_CENTER);
    shipBarCode.setBaseline(10f);
    shipBarCode.setBarHeight(50f);
    shipBarCode.setCode("111111111111");
    document.add(shipBarCode.createImageWithBarcode(cb, Color.black, Color.blue));

    document.add(p);
    document.close();
}