Example usage for java.awt FlowLayout FlowLayout

List of usage examples for java.awt FlowLayout FlowLayout

Introduction

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

Prototype

public FlowLayout() 

Source Link

Document

Constructs a new FlowLayout with a centered alignment and a default 5-unit horizontal and vertical gap.

Usage

From source file:ruc.edu.window.DynamicDataDemo2.java

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title.//from   ww w  .  j  a  va 2  s. c om
 */
public DynamicDataDemo2(final String title) {

    super(title);
    this.series1 = new TimeSeries("Random 1");
    this.series2 = new TimeSeries("Random 2");
    final TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1);
    final TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2);
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Dynamic Data Demo 2", "Time", "Value",
            dataset1, true, true, false);
    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainPannable(true);
    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    //axis.setAutoRangeMinimumSize(600000.0);
    axis.setFixedAutoRange(5000.0); // 60 seconds

    plot.setDataset(1, dataset2);
    //final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2");
    /// rangeAxis2.setAutoRangeIncludesZero(false);
    plot.setRenderer(0, new DefaultXYItemRenderer());
    plot.setRenderer(1, new DefaultXYItemRenderer());

    //plot.setRangeAxis(1, rangeAxis2);
    plot.mapDatasetToRangeAxis(1, 0);

    plot.getRenderer().setSeriesPaint(0, new Color(91, 155, 213));
    plot.getRenderer(1).setSeriesPaint(0, Color.BLUE);

    XYLineAndShapeRenderer render2 = new XYLineAndShapeRenderer() {
        Stroke soild = new BasicStroke(2.0f);
        Stroke dashed = new BasicStroke(10.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                new float[] { 10.0f }, 0.0f);

        @Override
        public Stroke getItemStroke(int row, int column) {
            return dashed;
        }
    };

    plot.setRenderer(1, render2);

    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JButton button1 = new JButton("Add To Series 1");
    button1.setActionCommand("ADD_DATA_1");
    button1.addActionListener(this);

    final JButton button2 = new JButton("Add To Series 2");
    button2.setActionCommand("ADD_DATA_2");
    button2.addActionListener(this);

    final JButton button3 = new JButton("Add To Both");
    button3.setActionCommand("ADD_BOTH");
    button3.addActionListener(this);

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(button1);
    buttonPanel.add(button2);
    buttonPanel.add(button3);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);

}