Example usage for java.awt Color gray

List of usage examples for java.awt Color gray

Introduction

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

Prototype

Color gray

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

Click Source Link

Document

The color gray.

Usage

From source file:Main.java

public static void main(String[] args) {
    JLabel label = new JLabel("First Name");
    label.setForeground(Color.gray);

    JFrame frame = new JFrame();
    frame.add(label);/*from   w  w w. j a v  a 2  s . c  o m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20, 20, 500, 500);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JLabel label = new JLabel("First Name");
    label.setForeground(Color.GRAY);

    JFrame frame = new JFrame();
    frame.add(label);/*from  w  ww  . j av  a2  s  .c om*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20, 20, 500, 500);
    frame.setVisible(true);
}

From source file:BorderExample.java

public static void main(String[] args) {
    JPanel panel = new JPanel(new BorderLayout());
    JPanel top = new JPanel();

    top.setBackground(Color.gray);
    top.setPreferredSize(new Dimension(250, 150));
    panel.add(top);//www  .j  a  va  2 s  .c o  m

    panel.setBorder(new EmptyBorder(new Insets(10, 20, 30, 40)));
    JFrame f = new JFrame();
    f.add(panel);
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame();
    frame.setTitle("JLabel Test");
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel("First Name");
    label.setFont(new Font("Courier New", Font.ITALIC, 12));
    label.setForeground(Color.GRAY);

    frame.add(label);/*from w  ww .ja va 2 s  .c o  m*/
    frame.pack();
    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;
        }//from   w  w  w. ja  va2s  . c o  m
    };
    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:TransparencyPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {/*from   www  .j a  v  a 2  s. c  om*/
        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:Main.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;
        }//  ww  w.ja  v  a 2 s.  c o m
    };
    LayoutManager overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);

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

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

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

    frame.add(panel, BorderLayout.CENTER);

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

From source file:ComplexRenderingSample.java

public static void main(String args[]) {

    Object elements[][] = {//  ww  w  .  java  2s  .  co m
            { 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:Main.java

public static void main(String... args) {
    JTextPane tPane = new JTextPane();
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    appendToPane(tPane, "this is a test.\n", Color.RED, Color.WHITE);
    appendToPane(tPane, "this is a test \n", Color.PINK, Color.BLUE);
    appendToPane(tPane, "test", Color.GRAY, Color.BLACK);
    appendToPane(tPane, "test", Color.RED, Color.BLUE);
    appendToPane(tPane, "test", Color.RED, Color.YELLOW);

    f.getContentPane().add(tPane);//from  ww  w  .ja  v  a  2s  .  c  o  m

    f.pack();
    f.setVisible(true);
}

From source file:ColorComboBox.java

public static void main(String args[]) {
    Color colors[] = { Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green,
            Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow };
    JFrame frame = new JFrame("Color JComboBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final JComboBox comboBox = new JComboBox(colors);
    comboBox.setMaximumRowCount(5);/*from www  .  j a v  a  2s  .c  o  m*/
    comboBox.setEditable(true);
    comboBox.setRenderer(new ColorCellRenderer());
    Color color = (Color) comboBox.getSelectedItem();
    ComboBoxEditor editor = new ColorComboBoxEditor(color);
    comboBox.setEditor(editor);
    contentPane.add(comboBox, BorderLayout.NORTH);

    final JLabel label = new JLabel();
    label.setOpaque(true);
    label.setBackground((Color) comboBox.getSelectedItem());
    contentPane.add(label, BorderLayout.CENTER);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color selectedColor = (Color) comboBox.getSelectedItem();
            label.setBackground(selectedColor);
        }
    };
    comboBox.addActionListener(actionListener);

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