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:gov.loc.repository.bagger.ui.NewBagFrame.java

private JPanel createComponents() {
    TitlePane titlePane = new TitlePane();
    initStandardCommands();//from   ww w.  j  a  v a2s .c o  m
    JPanel pageControl = new JPanel(new BorderLayout());
    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);

    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);
    JComponent buttonBar = createButtonBar();
    pageControl.add(buttonBar, BorderLayout.SOUTH);

    this.pack();
    return pageControl;
}

From source file:charts.Chart.java

public static void Histogram(IntervalXYDataset dataset, String title, String x_axis_label,
        String y_axis_label) {//  w  w  w. ja  v  a2s . c o  m
    JFrame chartwindow = new JFrame(title);
    JFreeChart jfreechart = ChartFactory.createHistogram(title, x_axis_label, y_axis_label, dataset,
            PlotOrientation.VERTICAL, true, false, false);

    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 void GraficoBarras() {
    JFrame janela = new JFrame("Exemplo de Grfico de Barras");

    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    defaultcategorydataset.addValue(212D, "Classes", "JDK 1.0");
    defaultcategorydataset.addValue(504D, "Classes", "JDK 1.1");
    defaultcategorydataset.addValue(1520D, "Classes", "SDK 1.2");
    defaultcategorydataset.addValue(1842D, "Classes", "SDK 1.3");
    defaultcategorydataset.addValue(2991D, "Classes", "SDK 1.4");

    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Java Standard Class Library", "Release",
            "Class Count", defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false);

    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    janela.setContentPane(jpanel);//from ww w. jav  a  2  s. c o  m
    janela.pack();
    RefineryUtilities.centerFrameOnScreen(janela);
    janela.setVisible(true);

}

From source file:charts.Chart.java

public static void GraficoTorta() {
    JFrame janela = new JFrame("Exemplo de Grfico de Torta");

    DefaultPieDataset pieDataset = new DefaultPieDataset();
    pieDataset.setValue("JavaWorld", new Integer(75));
    pieDataset.setValue("Other", new Integer(25));

    JFreeChart jfreechart = ChartFactory.createPieChart("Sample Pie Chart", // Title
            pieDataset, // Dataset
            true, // Show legend
            false, // Tooltips
            false // url
    );//  ww  w.j a  v  a2  s  . c om

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

}

From source file:charts.Chart.java

public static void BarChart(DefaultCategoryDataset dataset, String title, String x_axis_label,
        String y_axis_label, boolean showlegend) {
    JFrame chartwindow = new JFrame(title);
    JFreeChart jfreechart = ChartFactory.createStackedBarChart(title, x_axis_label, y_axis_label, dataset,
            PlotOrientation.HORIZONTAL, showlegend, true, false);

    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.black);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setLabelFont(new Font("SansSerif", Font.BOLD, 12));

    CategoryAxis domainaxis = categoryplot.getDomainAxis();
    domainaxis.setLabelFont(new Font("SansSerif", Font.BOLD, 12));

    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    chartwindow.setContentPane(jpanel);//from  w w  w  .  j  a v  a  2s. c om
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(true);
}

From source file:charts.Chart.java

public static void StepChart(CategoryDataset dataset, String title, String x_axis_label, String y_axis_label,
        boolean showlegend, float maxvalue, float minvalue) {
    JFrame chartwindow = new JFrame(title);
    CategoryItemRenderer renderer = new CategoryStepRenderer(true);
    CategoryAxis domainAxis = new CategoryAxis(x_axis_label);
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    CategoryPlot categoryplot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
    JFreeChart jfreechart = new JFreeChart(title, categoryplot);

    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.black);
    //NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    if (minvalue == 0 && maxvalue == 0) {
        rangeAxis.setAutoRange(true);/*from  w ww . j  av  a  2  s .  c  om*/
    } else {
        rangeAxis.setRange(minvalue, maxvalue);
    }
    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 void MultipleLineChart(XYSeriesCollection datasets, String title, String x_axis_label,
        String y_axis_label) {/*from  w ww .j av  a2 s .c o  m*/
    JFrame chartwindow = new JFrame(title);
    JFreeChart jfreechart = ChartFactory.createXYLineChart(title, x_axis_label, y_axis_label, datasets,
            PlotOrientation.VERTICAL, true, true, true);

    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.black);

    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);

    XYLineAndShapeRenderer lineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    lineandshaperenderer.setShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setFillPaint(Color.white);

    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 void MultipleLineChart(XYDataset[] datasets, String title, String x_axis_label,
        String y_axis_label, boolean showlegend, float maxvalue, float minvalue) {
    JFrame chartwindow = new JFrame(title);
    CombinedDomainXYPlot parent = new CombinedDomainXYPlot(new NumberAxis(x_axis_label));
    for (int i = 0; i < datasets.length; i++) {
        XYItemRenderer renderer = new StandardXYItemRenderer();
        renderer.setBaseSeriesVisibleInLegend(showlegend);

        XYPlot subplot = new XYPlot(datasets[i], null, new NumberAxis(y_axis_label), renderer);
        NumberAxis axis = (NumberAxis) subplot.getRangeAxis();
        //axis.setTickLabelFont(new Font("SansSerif", Font.BOLD,12));
        //axis.setLabelFont(new Font("SansSerif", Font.PLAIN,10));
        axis.setAutoRangeIncludesZero(true);
        axis.setLabelFont(new Font("SansSerif", Font.BOLD, 12));

        NumberAxis daxis = (NumberAxis) parent.getDomainAxis();
        daxis.setLabelFont(new Font("SansSerif", Font.BOLD, 12));

        parent.add(subplot, 1);/*w  w w  .j a va  2 s. c  o m*/
    }
    JFreeChart jfreechart = new JFreeChart(title, parent);
    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 void LineChart(double[][] data, String title_validation, String title, String x_axis_label,
        String y_axis_label) {/*from w w  w  .  j  av a  2 s. c o m*/

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < data.length; i++) {
        dataset.addValue(data[i][1], title_validation, String.valueOf(data[i][2]));
    }
    JFrame chartwindow = new JFrame(title);
    JFreeChart jfreechart = ChartFactory.createLineChart(title, x_axis_label, y_axis_label, dataset,
            PlotOrientation.VERTICAL, true, true, false);

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

    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setFillPaint(Color.white);

    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 void PontosXY() {

    XYSeries series2 = new XYSeries("Max Value");
    series2.add(30.0, 15.0);/*  ww  w  . j a  v  a2 s  .c  o  m*/
    series2.add(20.0, 30.0);
    series2.add(10.0, 75.0);
    series2.add(40.0, 23.0);
    series2.add(5.0, 50.0);
    series2.add(25.0, 45.0);

    XYSeries series3 = new XYSeries("Min Value");
    series3.add(10.0, 15.0);

    XYSeriesCollection series = new XYSeriesCollection();
    series.addSeries(series2);
    series.addSeries(series3);

    JFreeChart jfreechart = ChartFactory.createScatterPlot("Sample XY Chart", // Title
            "Height", // X-Axis label
            "Weight", // Y-Axis label
            series, // Dataset
            PlotOrientation.VERTICAL, true, // Show legend
            false, false);
    JFrame janela = new JFrame("Example of the XY series graphic");
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    janela.setContentPane(jpanel);
    janela.pack();
    RefineryUtilities.centerFrameOnScreen(janela);
    janela.setVisible(true);
}