Example usage for javax.swing JPanel setPreferredSize

List of usage examples for javax.swing JPanel setPreferredSize

Introduction

In this page you can find the example usage for javax.swing JPanel setPreferredSize.

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:charts.Chart.java

public static void ScatterPlot(XYSeriesCollection dataset, String title, String xAxisLabel, String yAxisLabel) {
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setAutoRangeIncludesZero(false);
    XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator();
    XYURLGenerator urlGenerator = new StandardXYURLGenerator();
    XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);//(boolean lines, boolean shapes)
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    //plot.setDataset(dataset);
    //plot.setDomainAxis(xAxis);
    //plot.setRangeAxis(yAxis);
    //plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);//true==legend
    //INVERTER AS CORES DOS PONTOS E LEGENDA.
    if (dataset.getSeriesCount() > 1) {
        Shape s0 = plot.getLegendItems().get(0).getShape();
        Shape s1 = plot.getLegendItems().get(1).getShape();
        renderer.setSeriesShape(0, s1);//  w w  w . j a  va 2  s  .  c  o  m
        renderer.setSeriesShape(1, s0);
        Paint p0 = plot.getLegendItems().get(0).getLinePaint();
        Paint p1 = plot.getLegendItems().get(1).getLinePaint();
        renderer.setSeriesPaint(0, p1);
        renderer.setSeriesPaint(1, p0);
    }
    //FIM DA INVERSAO.

    JFrame chartwindow = new JFrame(title);
    JPanel jpanel = new ChartPanel(chart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(true);
}

From source file:charts.Chart.java

public static JFreeChart MultipleStepChart(CategoryDataset[] datasets, String title, String x_axis_label,
        String y_axis_label, boolean showlegend, float maxvalue, float minvalue, boolean showchart) {

    CategoryAxis domainAxis = new CategoryAxis(x_axis_label);
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    if (minvalue == 0 && maxvalue == 0) {
        rangeAxis.setAutoRange(true);/* w w  w .  j  a  va2  s .co  m*/
    } else {
        rangeAxis.setRange(minvalue, maxvalue);
    }
    CombinedDomainCategoryPlot parent = new CombinedDomainCategoryPlot(new CategoryAxis(x_axis_label));

    for (int i = 0; i < datasets.length; i++) {
        CategoryItemRenderer renderer = new CategoryStepRenderer(true);
        renderer.setBaseStroke(new BasicStroke(2.0f));
        CategoryPlot subplot = new CategoryPlot(datasets[i], domainAxis, rangeAxis, renderer);
        subplot.setBackgroundPaint(Color.white);
        subplot.setRangeGridlinePaint(Color.black);
        subplot.setDomainGridlinesVisible(true);
        //subplot.setDrawSharedDomainAxis(true);
        parent.add(subplot, 1);
    }

    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));

    if (showchart) {
        JFrame chartwindow = new JFrame(title);
        chartwindow.setContentPane(jpanel);
        chartwindow.pack();
        RefineryUtilities.centerFrameOnScreen(chartwindow);
        chartwindow.setVisible(true);
    }
    return jfreechart;
}

From source file:cool.pandora.modeller.ui.jpanel.base.NewBagFrame.java

/**
 * createComponents./*from w  ww .j  av a2 s .  c om*/
 *
 * @return pageControl
 */
private JPanel createComponents() {
    final TitlePane titlePane = new TitlePane();
    initStandardCommands();
    final JPanel pageControl = new JPanel(new BorderLayout());
    final JPanel titlePaneContainer = new JPanel(new BorderLayout());
    titlePane.setTitle(bagView.getPropertyMessage("NewBagFrame.title"));
    titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("NewBagFrame" + ".description")));
    titlePaneContainer.add(titlePane.getControl());
    titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
    pageControl.add(titlePaneContainer, BorderLayout.NORTH);

    final JPanel contentPane = new JPanel();
    contentPane.setLayout(new GridBagLayout());

    int row = 0;
    layoutBagVersionSelection(contentPane, row++);
    layoutProfileSelection(contentPane, row++);

    if (getPreferredSize() != null) {
        contentPane.setPreferredSize(getPreferredSize());
    }

    GuiStandardUtils.attachDialogBorder(contentPane);
    pageControl.add(contentPane);
    final JComponent buttonBar = createButtonBar();
    pageControl.add(buttonBar, BorderLayout.SOUTH);

    this.pack();
    return pageControl;
}

From source file:charts.Chart.java

public static JFreeChart MultipleSplineLineChart(XYDataset[] datasets, String title, String x_axis_label,
        String y_axis_label, boolean showlegend, float maxvalue, float minvalue, boolean showchart) {

    ValueAxis domainAxis = new NumberAxis(x_axis_label);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    if (minvalue == 0 && maxvalue == 0) {
        rangeAxis.setAutoRange(true);//  w w w  .ja  v a 2  s .co m
    } else {
        rangeAxis.setRange(minvalue, maxvalue);
    }

    //define o grafo combinado, determinando o label do eixo x.
    CombinedDomainXYPlot parent = new CombinedDomainXYPlot(domainAxis);

    for (int i = 0; i < datasets.length; i++) {
        XYSplineRenderer renderer = new XYSplineRenderer();
        renderer.setBaseStroke(new BasicStroke(2.0f));
        renderer.setBaseSeriesVisibleInLegend(showlegend);
        renderer.setShapesVisible(true);
        XYPlot subplot = new XYPlot(datasets[i], domainAxis, rangeAxis, renderer);
        subplot.setBackgroundPaint(Color.white);
        subplot.setRangeGridlinePaint(Color.black);
        subplot.setDomainGridlinesVisible(true);
        parent.add(subplot, 1);
    }
    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));

    if (showchart) {
        JFrame chartwindow = new JFrame(title);
        chartwindow.setContentPane(jpanel);
        chartwindow.pack();
        RefineryUtilities.centerFrameOnScreen(chartwindow);
        chartwindow.setVisible(true);
    }
    return jfreechart;
}

From source file:charts.Chart.java

public static Vector MultipleLineChart(CategoryDataset[] datasets, String title, String x_axis_label,
        String y_axis_label, boolean showlegend, float maxvalue, float minvalue, boolean showchart) {

    CategoryAxis domainAxis = new CategoryAxis(x_axis_label);
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    if (minvalue == 0 && maxvalue == 0) {
        rangeAxis.setAutoRange(true);/*w  w  w.jav  a 2 s.  co  m*/
    } else {
        rangeAxis.setRange(minvalue, maxvalue);
    }
    CombinedDomainCategoryPlot parent = new CombinedDomainCategoryPlot(new CategoryAxis(x_axis_label));

    for (int i = 0; i < datasets.length; i++) {
        CategoryItemRenderer renderer = new DefaultCategoryItemRenderer();//new CategoryStepRenderer(true);
        renderer.setBaseStroke(new BasicStroke(2.0f));
        renderer.setBaseSeriesVisibleInLegend(showlegend);
        CategoryPlot subplot = new CategoryPlot(datasets[i], domainAxis, rangeAxis, renderer);
        subplot.setBackgroundPaint(Color.white);
        subplot.setRangeGridlinePaint(Color.black);
        subplot.setDomainGridlinesVisible(true);
        //subplot.setDrawSharedDomainAxis(true);
        parent.add(subplot, 1);
    }

    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));

    //if (showchart) {
    JFrame chartwindow = new JFrame(title);
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(true);
    //}
    Vector res = new Vector();
    res.add(0, jfreechart);
    res.add(1, chartwindow);
    return res;
}

From source file:charts.Chart.java

public static void LineChart(DefaultCategoryDataset dataset, String title, String x_axis_label,
        String y_axis_label, boolean showlegend, float maxvalue, float minvalue) {

    JFrame chartwindow = new JFrame(title);

    JFreeChart jfreechart = ChartFactory.createLineChart(title, x_axis_label, y_axis_label, dataset,
            PlotOrientation.VERTICAL, showlegend, // include legend
            true, // tooltips
            true // urls
    );/*from www  .  j av a2 s.  c  o  m*/

    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.black);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    CategoryPlot plot = (CategoryPlot) jfreechart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    if (minvalue == 0 && maxvalue == 0) {
        rangeAxis.setAutoRangeIncludesZero(true);
    } else {
        rangeAxis.setRange(minvalue, maxvalue);
    }
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseStroke(new BasicStroke(2.0f));
    lineandshaperenderer.setShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setFillPaint(Color.white);

    //GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.MAGENTA, 0.0f, 0.0f, Color.MAGENTA);
    //lineandshaperenderer.setSeriesPaint(0, gp1);
    //ou
    lineandshaperenderer.setSeriesPaint(0, Color.RED);

    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(true);
}

From source file:charts.Chart.java

public static JFreeChart MultipleStepChartOverlayed(XYDataset[] datasets1, XYDataset[] datasets2, String title,
        String x_axis_label, String y_axis_label, boolean showlegend, float maxvalue, float minvalue,
        boolean showchart) {

    ValueAxis domainAxis = new NumberAxis(x_axis_label);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    if (minvalue == 0 && maxvalue == 0) {
        rangeAxis.setAutoRange(true);//from  w  ww.  ja v  a 2s  . c o m
    } else {
        rangeAxis.setRange(minvalue, maxvalue);
    }

    //define o grafo combinado, determinando o label do eixo x.
    CombinedDomainXYPlot parent = new CombinedDomainXYPlot(domainAxis);

    for (int i = 0; i < datasets1.length; i++) {
        XYItemRenderer renderer1 = new XYStepRenderer();
        renderer1.setBaseStroke(new BasicStroke(2.0f));
        renderer1.setBaseSeriesVisibleInLegend(showlegend);
        XYPlot subplot = new XYPlot(datasets1[i], domainAxis, rangeAxis, renderer1);
        subplot.setBackgroundPaint(Color.white);
        subplot.setRangeGridlinePaint(Color.black);
        subplot.setDomainGridlinesVisible(true);

        XYSplineRenderer renderer2 = new XYSplineRenderer();
        renderer2.setSeriesPaint(0, Color.LIGHT_GRAY);
        renderer2.setBaseStroke(new BasicStroke(2.0f));
        renderer2.setShapesVisible(true);
        renderer2.setBaseSeriesVisibleInLegend(false);
        subplot.setDataset(1, datasets2[i]);
        subplot.setRenderer(1, renderer2);
        parent.add(subplot, 1);
    }
    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));

    if (showchart) {
        JFrame chartwindow = new JFrame(title);
        chartwindow.setContentPane(jpanel);
        chartwindow.pack();
        RefineryUtilities.centerFrameOnScreen(chartwindow);
        chartwindow.setVisible(true);
    }
    return jfreechart;
}

From source file:charts.Chart.java

public static Vector MultipleStepChartOverlayed(CategoryDataset[] datasets1, CategoryDataset[] datasets2,
        String title, String x_axis_label, String y_axis_label, boolean showlegend, float maxvalue,
        float minvalue, boolean showchart) {

    CategoryAxis domainAxis = new CategoryAxis(x_axis_label);
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    //if (minvalue == 0 && maxvalue == 0) {
    //    rangeAxis.setAutoRange(true);
    //} else {/*from   w  w w.  ja va2s  .  c o m*/
    //    rangeAxis.setRange(minvalue, maxvalue);
    //}
    rangeAxis.setAutoRange(true);

    CombinedDomainCategoryPlot parent = new CombinedDomainCategoryPlot(new CategoryAxis(x_axis_label));

    for (int i = 0; i < datasets1.length; i++) {
        CategoryItemRenderer renderer1 = new CategoryStepRenderer(true);
        renderer1.setBaseStroke(new BasicStroke(2.0f));
        renderer1.setBaseSeriesVisibleInLegend(showlegend);

        CategoryPlot subplot = new CategoryPlot(datasets1[i], domainAxis, rangeAxis, renderer1);
        subplot.setBackgroundPaint(Color.white);
        subplot.setRangeGridlinePaint(Color.black);
        subplot.setDomainGridlinesVisible(true);

        DefaultCategoryItemRenderer renderer2 = new DefaultCategoryItemRenderer();
        renderer2.setSeriesPaint(0, Color.LIGHT_GRAY);
        renderer2.setBaseStroke(new BasicStroke(2.0f));
        renderer2.setShapesVisible(true);
        renderer2.setBaseSeriesVisibleInLegend(false);

        subplot.setDataset(1, datasets2[i]);
        subplot.setRenderer(1, renderer2);
        //subplot.setDrawSharedDomainAxis(true);
        parent.add(subplot, 1);
    }

    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));

    //if (showchart) {
    JFrame chartwindow = new JFrame(title);
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(true);
    //}
    Vector res = new Vector();
    res.add(0, jfreechart);
    res.add(1, chartwindow);
    return res;
}

From source file:com.twocents.test.ui.chart.ChartMain.java

/**
 * Creates a new demo instance./*from ww  w  .  j  av  a2  s  . co  m*/
 * 
 * @param title
 *            the frame title.
 * @throws CoreException 
 */
public ChartMain(String title) throws CoreException {

    super(title);
    JPanel panel = new JPanel(new GridLayout(1, 1));
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Section 1", 23.3);
    dataset.setValue("Section 2", 56.5);
    dataset.setValue("Section 3", 43.3);
    dataset.setValue("Section 4", 11.1);

    int sizeX = 600;
    int sizeY = 600;
    String titleChart = "Test";
    JFreeChart chart = BuildChart.createChartPie(titleChart, dataset);

    panel.add(new ChartPanel(chart));

    panel.setPreferredSize(new Dimension(sizeX, sizeY));
    setContentPane(panel);
}

From source file:moviedatas.View.SpiderWebChart.java

public void refreshChart(JPanel panel, int duration, double ratio, double score, double recency, int fbLikes) {
    panel.removeAll();//from ww  w.j ava  2s.  c  om
    panel.revalidate(); // This removes the old chart 
    spiderChart = createChart(createDataset(duration, ratio, score, recency, fbLikes));
    spiderChart.clearSubtitles();
    chartPanel = new ChartPanel(spiderChart);
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel);
    panel.setPreferredSize(new Dimension(300, 300));
    panel.repaint(); // This method makes the new chart appear
}