Example usage for java.awt Color WHITE

List of usage examples for java.awt Color WHITE

Introduction

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

Prototype

Color WHITE

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

Click Source Link

Document

The color white.

Usage

From source file:TextFieldsPDF.java

License:asdf

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate());
    try {/*from  w  ww . ja  v  a2  s  .com*/
        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:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame();
    f.add(new JComponent() {
        public void paintComponent(Graphics g) {

            // Some parameters.
            String text = "Some Label";
            int centerX = 150, centerY = 100;
            int ovalWidth = 200, ovalHeight = 100;

            // Draw oval
            g.setColor(Color.BLUE);
            g.fillOval(centerX - ovalWidth / 2, centerY - ovalHeight / 2, ovalWidth, ovalHeight);

            // Draw centered text
            FontMetrics fm = g.getFontMetrics();
            double textWidth = fm.getStringBounds(text, g).getWidth();
            g.setColor(Color.WHITE);
            g.drawString(text, (int) (centerX - textWidth / 2), (int) (centerY + fm.getMaxAscent() / 2));

        }/*w  w  w  . ja v a 2s  .  co m*/
    });

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(300, 300);
    f.setVisible(true);
}

From source file:Main.java

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

    JPanel contentPane = new JPanel();

    JFormattedTextField ftf = new JFormattedTextField(NumberFormat.getNumberInstance());
    ftf.setColumns(10);//from w  w w  .ja  va2  s  .c o  m
    ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
    ftf.setValue(100);
    lastValidValue = "100";
    ftf.addCaretListener(e -> {
        System.out.println("Last Valid Value : " + lastValidValue);
        if (ftf.isEditValid()) {
            String latestValue = ftf.getText();
            System.out.println("Latest Value : " + latestValue);
            if (!(latestValue.equals(lastValidValue)))
                ftf.setBackground(Color.YELLOW.darker());
            else {
                lastValidValue = ftf.getText();
                ftf.setBackground(Color.WHITE);
            }
        } else {
            System.out.println("Invalid Edit Entered.");
        }
    });
    contentPane.add(ftf);
    frame.setContentPane(contentPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String s = "The quick brown fox jumps over the lazy dog!";
    BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    FontMetrics fm = g.getFontMetrics();
    Rectangle2D b = fm.getStringBounds(s, g);
    System.out.println(b);//w w w .  j a  v a  2  s. c  om
    bi = new BufferedImage((int) b.getWidth(), (int) (b.getHeight() + fm.getDescent()),
            BufferedImage.TYPE_INT_RGB);
    g = bi.getGraphics();
    g.drawString(s, 0, (int) b.getHeight());

    JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(bi)));

    // Technique 3 - JLabel
    JLabel l = new JLabel(s);
    l.setSize(l.getPreferredSize());
    bi = new BufferedImage(l.getWidth(), l.getHeight(), BufferedImage.TYPE_INT_RGB);
    g = bi.getGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, 400, 100);
    l.paint(g);

    JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(bi)));
}

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  www.  j a  va  2 s .  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  ww  w.  j  av a 2  s  . co  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);
}

From source file:edu.packt.neuralnet.som.Kohonen0DTest.java

public static void main(String[] args) {

    RandomNumberGenerator.seed = 0;/*from   ww  w.j  a v  a 2s .  c  o  m*/

    int numberOfInputs = 2;
    int numberOfNeurons = 10;
    int numberOfPoints = 100;

    double[][] rndDataSet = RandomNumberGenerator.GenerateMatrixBetween(numberOfPoints, numberOfInputs, -10.0,
            10.0);

    Kohonen kn0 = new Kohonen(numberOfInputs, numberOfNeurons, new UniformInitialization(-1.0, 1.0), 0);

    NeuralDataSet neuralDataSet = new NeuralDataSet(rndDataSet, 2);

    CompetitiveLearning complrn = new CompetitiveLearning(kn0, neuralDataSet,
            LearningAlgorithm.LearningMode.ONLINE);
    complrn.show2DData = true;
    complrn.printTraining = true;
    complrn.setLearningRate(0.003);
    complrn.setMaxEpochs(10000);
    complrn.setReferenceEpoch(3000);

    try {
        String[] seriesNames = { "Training Data" };
        Paint[] seriesColor = { Color.WHITE };

        Chart chart = new Chart("Training", rndDataSet, seriesNames, 0, seriesColor);
        ChartFrame frame = new ChartFrame("Training", chart.scatterPlot("X", "Y"));
        frame.pack();
        frame.setVisible(true);
        //System.in.read();
        complrn.setPlot2DFrame(frame);
        complrn.showPlot2DData();
        //System.in.read();
        complrn.train();
    } catch (Exception ne) {

    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    int SIZE = 14;
    String FONT = "Dialog";

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextPane tp = new JTextPane();
    tp.setFont(new Font(FONT, Font.PLAIN, SIZE));
    tp.setPreferredSize(new Dimension(400, 300));
    StyledDocument doc = tp.getStyledDocument();
    Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    Style boldStyle = doc.addStyle("bold", defaultStyle);
    StyleConstants.setBold(boldStyle, true);
    String boldText = "this is bold test";
    String plainText = "this is plain.";

    doc.insertString(doc.getLength(), boldText, boldStyle);
    doc.insertString(doc.getLength(), plainText, defaultStyle);

    JPanel panel = new JPanel();
    panel.add(tp);//w  w w .ja  v a 2 s .  c  om

    JComboBox<String> zoomCombo = new JComboBox<String>(
            new String[] { "0.75", "1.00", "1.50", "1.75", "2.00" });
    zoomCombo.addActionListener(e -> {
        String s = (String) zoomCombo.getSelectedItem();
        double scale = new Double(s).doubleValue();
        int size = (int) (SIZE * scale);
        tp.setFont(new Font(FONT, Font.PLAIN, size));
    });
    zoomCombo.setSelectedItem("1.00");
    JPanel optionsPanel = new JPanel();
    optionsPanel.add(zoomCombo);
    panel.setBackground(Color.WHITE);
    frame.add(panel, BorderLayout.CENTER);
    frame.add(optionsPanel, BorderLayout.NORTH);
    frame.pack();
    frame.setVisible(true);
}

From source file:edu.packt.neuralnet.som.Kohonen1DTest.java

public static void main(String[] args) {

    RandomNumberGenerator.seed = 0;//from  ww  w. j  av  a  2s. c  o m

    int numberOfInputs = 2;
    int numberOfNeurons = 20;
    int numberOfPoints = 1000;

    double[][] rndDataSet = RandomNumberGenerator.GenerateMatrixBetween(numberOfPoints, numberOfInputs, -100.0,
            100.0);

    for (int i = 0; i < numberOfPoints; i++) {
        rndDataSet[i][0] = i;
        rndDataSet[i][0] += RandomNumberGenerator.GenerateNext();
        rndDataSet[i][1] = Math.cos(i / 100.0) * 1000;
        rndDataSet[i][1] += RandomNumberGenerator.GenerateNext() * 400;
    }

    Kohonen kn1 = new Kohonen(numberOfInputs, numberOfNeurons, new UniformInitialization(0.0, 1000.0), 1);

    NeuralDataSet neuralDataSet = new NeuralDataSet(rndDataSet, 2);

    CompetitiveLearning complrn = new CompetitiveLearning(kn1, neuralDataSet,
            LearningAlgorithm.LearningMode.ONLINE);
    complrn.show2DData = true;
    complrn.printTraining = true;
    complrn.setLearningRate(0.3);
    complrn.setMaxEpochs(10000);
    complrn.setReferenceEpoch(3000);
    try {
        String[] seriesNames = { "Training Data" };
        Paint[] seriesColor = { Color.WHITE };

        Chart chart = new Chart("Training", rndDataSet, seriesNames, 0, seriesColor, Chart.SeriesType.DOTS);
        ChartFrame frame = new ChartFrame("Training", chart.scatterPlot("X", "Y"));
        frame.pack();
        frame.setVisible(true);

        complrn.setPlot2DFrame(frame);
        complrn.showPlot2DData();
        System.in.read();

        complrn.train();
    } catch (Exception ne) {

    }
}

From source file:org.jfree.graphics2d.demo.BufferedImageDemo.java

/**
 * Starting point for the demo./*w w  w. j  a  v  a2s .  com*/
 * 
 * @param args  ignored.
 * 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    BufferedImage image = new BufferedImage(600, 400, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    ImageIcon icon = new ImageIcon(BufferedImageDemo.class.getResource("jfree_chart_1.jpg"));
    g2.rotate(Math.PI / 12);
    g2.setStroke(new BasicStroke(2.0f));
    g2.setPaint(Color.WHITE);
    g2.fill(new Rectangle(0, 0, 600, 400));
    g2.setPaint(Color.RED);
    g2.draw(new Rectangle(0, 0, 600, 400));
    g2.drawImage(icon.getImage(), 10, 20, null);
    ImageIO.write(image, "png", new File("image-test.png"));
}