Example usage for java.awt Color RED

List of usage examples for java.awt Color RED

Introduction

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

Prototype

Color RED

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

Click Source Link

Document

The color red.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JTable table = new JTable();

    table.setShowGrid(false);//Don't show any grid lines

    //Show only vertical grid lines
    table.setShowGrid(false);/*w  ww  .  j a v  a 2  s.  c  om*/
    table.setShowVerticalLines(true);

    //Show only horizontal grid lines

    table.setShowGrid(false);
    table.setShowHorizontalLines(true);

    //Set the grid color

    table.setGridColor(Color.red);

    //Show both horizontal and vertical grid lines (the default)
    table.setShowGrid(true);
}

From source file:MainClass.java

public static void main(String argv[]) {

    ColorPane pane = new ColorPane();
    for (int n = 1; n <= 400; n += 1) {
        if (isPrime(n)) {
            pane.append(Color.red, String.valueOf(n) + ' ');
        } else if (isPerfectSquare(n)) {
            pane.append(Color.blue, String.valueOf(n) + ' ');
        } else {/*from   ww  w  .  j a  va  2  s  .  co  m*/
            pane.append(Color.black, String.valueOf(n) + ' ');
        }
    }

    JFrame f = new JFrame("ColorPane example");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(new JScrollPane(pane));
    f.setSize(600, 400);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    SplashScreen splash = SplashScreen.getSplashScreen();
    Graphics2D g = (Graphics2D) splash.createGraphics();
    System.out.println(splash.getBounds());
    Dimension dim = splash.getSize();
    for (int i = 0; i < 100; i++) {
        g.setColor(Color.RED);
        g.fillRect(50, 50, dim.width - 100, dim.height - 100);
        splash.update();//w  ww.java  2 s .com
        try {
            Thread.sleep(250);
        } catch (InterruptedException ignored) {
        }
    }
    JFrame frame = new JFrame("Splash Me2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel("Hello, Splash", JLabel.CENTER);
    frame.add(label, BorderLayout.CENTER);
    frame.setSize(300, 95);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Color colors[] = { Color.GREEN, Color.ORANGE, Color.PINK, Color.RED, Color.WHITE, Color.YELLOW };
    JFrame frame = new JFrame("Color JComboBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JComboBox comboBox = new JComboBox(colors);
    comboBox.setMaximumRowCount(5);/*from w  ww.jav  a2  s  .  c o m*/
    comboBox.setEditable(true);
    comboBox.setRenderer(new ColorCellRenderer());
    frame.add(comboBox, BorderLayout.NORTH);

    final JLabel label = new JLabel();
    label.setOpaque(true);
    label.setBackground((Color) comboBox.getSelectedItem());
    frame.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);
}

From source file:Main.java

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

    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.RED);
    aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");

    JTextPane tPane1 = new JTextPane();
    tPane1.setCharacterAttributes(aset, false);

    f.add(tPane1, BorderLayout.CENTER);

    f.pack();/*from w  w  w  .  j  a v a 2s .  c o  m*/
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);

    Graphics g = img.getGraphics();
    g.setColor(Color.red);
    g.setFont(new Font("Arial", Font.BOLD, 14));
    g.drawString("Reference", 10, 80);

    int w = 100;/*from  w w  w  .  j  a v a2s. co  m*/
    int h = 100;
    int x = 1;
    int y = 1;

    int[] pixels = new int[w * h];
    PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);

    pg.grabPixels();
    BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

    for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
            bimg.setRGB(x + i, y + j, pixels[j * w + i]);
        }
    }

    FileOutputStream fout = new FileOutputStream("jpg.jpg");

    JPEGImageEncoder jencoder = JPEGCodec.createJPEGEncoder(fout);
    JPEGEncodeParam enParam = jencoder.getDefaultJPEGEncodeParam(bimg);

    enParam.setQuality(1.0F, true);
    jencoder.setJPEGEncodeParam(enParam);
    jencoder.encode(bimg);

    fout.close();

}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList(labels);
    jlist1.setVisibleRowCount(4);/*from w w  w .j a va 2  s  .c  o  m*/
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    jlist1.setSelectionForeground(Color.RED);

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

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist1 = new JList(labels);
    jlist1.setVisibleRowCount(4);/*ww w .j  av  a  2 s  .co m*/
    JScrollPane scrollPane1 = new JScrollPane(jlist1);
    frame.add(scrollPane1, BorderLayout.NORTH);

    jlist1.setSelectionBackground(Color.RED);

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

From source file:Main.java

public static void main(String[] args) {
    JTextArea textArea = new JTextArea(5, 30);
    textArea.setOpaque(false);/*w w  w . j a v a  2s. c  om*/

    JViewport viewport = new JViewport() {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            int w = this.getWidth();
            int h = this.getHeight();
            g.setColor(Color.RED);
            g.fillRect(0, 0, w / 2, h / 2);
        }
    };

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewport(viewport);
    scrollPane.setViewportView(textArea);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(scrollPane);
    frame.setLocationByPlatform(true);
    frame.pack();
    frame.setVisible(true);
}

From source file:ATitledBorder.java

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

    Border thisBorder = BorderFactory.createTitledBorder("Easy");

    Border thatBorder1 = new LineBorder(Color.RED);
    Border thatBorder2 = new TitledBorder(thatBorder1, "Harder");

    Font font = new Font("Serif", Font.ITALIC, 12);
    Border thatBorder = new TitledBorder(thatBorder2, "Harder", TitledBorder.LEFT, TitledBorder.ABOVE_BOTTOM,
            font, Color.RED);//w  w  w. j  a v a  2 s  . c om

    JButton thisButton = new JButton("Easy");
    thisButton.setBorder(thisBorder);

    JButton thatButton = new JButton("Harder");
    thatButton.setBorder(thatBorder);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(1, 2));
    contentPane.add(thisButton);
    contentPane.add(thatButton);
    frame.setSize(300, 200);
    frame.setVisible(true);
}