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(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);//from www .j  a  v a 2s . com

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N);
    fileMenu.add(newMenuItem);

    JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Item", new MyIcon(Color.RED));
    caseMenuItem.setMnemonic(KeyEvent.VK_C);
    fileMenu.add(caseMenuItem);

    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:MovingIconTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();

    JButton b;//w w w.ja  va 2 s .c o  m
    Icon icon = new PieIcon(Color.red);
    b = new JButton("Default", icon);
    contentPane.add(b, BorderLayout.NORTH);
    b = new JButton("Text Left", icon);
    b.setHorizontalTextPosition(JButton.LEFT);
    contentPane.add(b, BorderLayout.SOUTH);
    b = new JButton("Text Up", icon);
    b.setHorizontalTextPosition(JButton.CENTER);
    b.setVerticalTextPosition(JButton.TOP);
    contentPane.add(b, BorderLayout.EAST);
    b = new JButton("Text Down", icon);
    b.setHorizontalTextPosition(JButton.CENTER);
    b.setVerticalTextPosition(JButton.BOTTOM);
    contentPane.add(b, BorderLayout.WEST);
    b = new JButton("Align Bottom Left", icon);
    b.setHorizontalAlignment(JButton.LEFT);
    b.setVerticalAlignment(JButton.BOTTOM);
    contentPane.add(b, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.show();
}

From source file:DnDDemo2.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new JPanel());

    JTextField textField = new JTextField(25);
    textField.setText("Let's swing higher");
    frame.add(textField);/*  w w w .  ja  v  a 2  s.  co m*/

    JTextArea textArea = new JTextArea("Demonstrating\ndrag and drop");
    textArea.setForeground(Color.red);
    frame.add(new JScrollPane(textArea));

    textArea.setDragEnabled(true);
    textField.setDragEnabled(true);
    TextColorTransferHandler transferHandler = new TextColorTransferHandler();
    textArea.setTransferHandler(transferHandler);
    textField.setTransferHandler(transferHandler);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) throws BadLocationException {
    JFrame jf = new JFrame("StyledText");
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container cp = jf.getContentPane();

    JTextPane pane = new JTextPane();
    SimpleAttributeSet set = new SimpleAttributeSet();
    StyleConstants.setBold(set, true);

    // Set the attributes before adding text
    pane.setCharacterAttributes(set, true);
    pane.setText("java2s.com ");

    set = new SimpleAttributeSet();
    StyleConstants.setItalic(set, true);
    StyleConstants.setForeground(set, Color.red);
    StyleConstants.setBackground(set, Color.blue);

    Document doc = pane.getStyledDocument();
    doc.insertString(doc.getLength(), "Swing ", set);

    set = new SimpleAttributeSet();
    StyleConstants.setFontSize(set, 24);

    doc.insertString(doc.getLength(), "Tutorial", set);

    JScrollPane scrollPane = new JScrollPane(pane);
    cp.add(scrollPane, BorderLayout.CENTER);

    jf.setSize(400, 300);/*from   w  w w  . j av  a2  s.  c o  m*/
    jf.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");
    Icon thatIcon = new ImageIcon("diamond.gif");
    Border thatBorder1 = new MatteBorder(18, 20, 18, 20, thatIcon);
    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);
    JButton thisButton = new JButton("Easy");
    thisButton.setBorder(thisBorder);/*from ww  w .ja v a  2s .c om*/
    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);
}

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Titled Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border thisBorder = BorderFactory.createTitledBorder("Easy");
    Icon thatIcon = MetalIconFactory.getFileChooserHomeFolderIcon();

    Border thatBorder1 = new MatteBorder(18, 20, 18, 20, thatIcon);
    Border thatBorder2 = new TitledBorder(thatBorder1, "Harder");

    Font font = new Font("Serif", Font.ITALIC, 12);
    Border thatBorder = new TitledBorder(thatBorder2, "Hardest", TitledBorder.LEFT, TitledBorder.ABOVE_BOTTOM,
            font, Color.RED);

    JButton thisButton = new JButton("Easy");
    thisButton.setBorder(thisBorder);//from   w w  w . j ava2s . co m
    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);
}

From source file:SimpleTableRowBackgroundPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate(), 50, 50, 50, 50);
    try {//  w  w w .  jav a2  s . com
        PdfWriter.getInstance(document, new FileOutputStream("SimpleTableRowBackgroundPDF.pdf"));
        document.open();

        SimpleTable table = new SimpleTable();
        SimpleCell row = new SimpleCell(SimpleCell.ROW);
        SimpleCell cell = new SimpleCell(SimpleCell.CELL);
        cell.add(new Paragraph("B"));
        cell.setWidth(100f);
        row.add(cell);

        cell = new SimpleCell(SimpleCell.CELL);
        cell.add(new Paragraph("A"));
        cell.setWidth(50f);

        row.add(cell);

        row.setBackgroundColor(Color.red);

        table.addElement(row);
        document.add(table);
    } catch (Exception e) {
        e.printStackTrace();
    }
    document.close();
}

From source file:EditableColorColumn.java

public static void main(String args[]) {

    Color choices[] = { Color.red, Color.orange, Color.yellow, Color.green, Color.blue, Color.magenta };
    ComboTableCellRenderer renderer = new ComboTableCellRenderer();
    JComboBox comboBox = new JComboBox(choices);
    comboBox.setRenderer(renderer);/* w w w. j av  a2  s. c om*/
    TableCellEditor editor = new DefaultCellEditor(comboBox);

    JFrame frame = new JFrame("Editable Color Table");
    TableModel model = new ColorTableModel();
    JTable table = new JTable(model);

    TableColumn column = table.getColumnModel().getColumn(3);
    column.setCellRenderer(renderer);
    column.setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:BorderSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Sample Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border bevelBorder = new BevelBorder(BevelBorder.RAISED, Color.red, Color.red.darker(), Color.pink,
            Color.pink.brighter());
    Border emptyBorder = new EmptyBorder(5, 10, 5, 10);
    Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED, Color.red, Color.pink);
    Border lineBorder = new LineBorder(Color.red, 5);
    Icon diamondIcon = new DiamondIcon(Color.red);
    Border matteBorder = new MatteBorder(5, 10, 5, 10, diamondIcon);
    Border softBevelBorder = new SoftBevelBorder(BevelBorder.RAISED, Color.red, Color.red.darker(), Color.pink,
            Color.pink.brighter());
    Font font = new Font("Serif", Font.ITALIC, 12);
    Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM,
            font, Color.red);/*  w ww.  ja  va  2 s.  c o  m*/
    Border compoundBorder = new CompoundBorder(lineBorder, matteBorder);

    JLabel bevelLabel = new JLabel("Bevel");
    bevelLabel.setBorder(bevelBorder);
    bevelLabel.setHorizontalAlignment(JLabel.CENTER);
    JLabel emptyLabel = new JLabel("Empty");
    emptyLabel.setBorder(emptyBorder);
    emptyLabel.setHorizontalAlignment(JLabel.CENTER);
    JLabel etchedLabel = new JLabel("Etched");
    etchedLabel.setBorder(etchedBorder);
    etchedLabel.setHorizontalAlignment(JLabel.CENTER);
    JLabel lineLabel = new JLabel("Line");
    lineLabel.setBorder(lineBorder);
    lineLabel.setHorizontalAlignment(JLabel.CENTER);
    JLabel matteLabel = new JLabel("Matte");
    matteLabel.setBorder(matteBorder);
    matteLabel.setHorizontalAlignment(JLabel.CENTER);
    JLabel softBevelLabel = new JLabel("Soft Bevel");
    softBevelLabel.setBorder(softBevelBorder);
    softBevelLabel.setHorizontalAlignment(JLabel.CENTER);
    JLabel titledLabel = new JLabel("Titled");
    titledLabel.setBorder(titledBorder);
    titledLabel.setHorizontalAlignment(JLabel.CENTER);
    JLabel compoundLabel = new JLabel("Compound");
    compoundLabel.setBorder(compoundBorder);
    compoundLabel.setHorizontalAlignment(JLabel.CENTER);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(2, 4, 5, 5));
    contentPane.add(bevelLabel);
    contentPane.add(emptyLabel);
    contentPane.add(etchedLabel);
    contentPane.add(lineLabel);
    contentPane.add(matteLabel);
    contentPane.add(softBevelLabel);
    contentPane.add(titledLabel);
    contentPane.add(compoundLabel);
    frame.setSize(400, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String s = new Date().toString();
    JTextPane jtp = new JTextPane();
    StyledDocument doc = (StyledDocument) jtp.getDocument();

    SimpleAttributeSet normal = new SimpleAttributeSet();
    StyleConstants.setFontFamily(normal, "SansSerif");
    StyleConstants.setFontSize(normal, 16);

    SimpleAttributeSet boldBlue = new SimpleAttributeSet(normal);
    StyleConstants.setBold(boldBlue, true);
    StyleConstants.setForeground(boldBlue, Color.blue);

    SimpleAttributeSet highAlert = new SimpleAttributeSet(boldBlue);
    StyleConstants.setFontSize(highAlert, 18);
    StyleConstants.setItalic(highAlert, true);
    StyleConstants.setForeground(highAlert, Color.red);

    doc.insertString(doc.getLength(), s + "\n", normal);
    doc.insertString(doc.getLength(), s + "\n", boldBlue);
    doc.insertString(doc.getLength(), s + "\n", highAlert);
    f.add(jtp);/* w ww .  ja v  a  2 s. c  o  m*/
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}