Example usage for javax.swing JFrame setMaximumSize

List of usage examples for javax.swing JFrame setMaximumSize

Introduction

In this page you can find the example usage for javax.swing JFrame setMaximumSize.

Prototype

public void setMaximumSize(Dimension maximumSize) 

Source Link

Document

Sets the maximum size of this component to a constant value.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setMaximumSize(new Dimension(350, 250));
    frame.addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent evt) {
            Dimension size = frame.getSize();
            Dimension max = frame.getMaximumSize();
            if (size.getWidth() > max.getWidth()) {
                frame.setSize((int) max.getWidth(), (int) size.getHeight());
            }/* w  w  w.ja v a2 s.  c  o  m*/
            if (size.getHeight() > max.getHeight()) {
                frame.setSize((int) size.getWidth(), (int) max.getHeight());
            }
        }
    });
    frame.setSize(200, 100);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:br.com.ant.system.util.ChartUtil.java

public void createTempoTotalExecucao(Set<EstatisticaColetor> estatisticas) {

    // Create a simple XY chart
    XYSeries series = new XYSeries("Formiga");

    JFrame frame = new JFrame();

    for (EstatisticaColetor e : estatisticas) {
        series.add(e.getId(), e.getTempoExecucao());
    }/*from  www  . ja v a 2 s .c o m*/

    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("Tempo total de Execuo", "Execuo", "Tempo (ms)",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    frame.getContentPane().add(new ChartPanel(chart));

    frame.setPreferredSize(new Dimension(600, 600));
    frame.setMinimumSize(new Dimension(600, 600));
    frame.setMaximumSize(new Dimension(600, 600));
    frame.setVisible(true);

    try {
        ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }
}

From source file:br.com.ant.system.util.ChartUtil.java

public void createCaminhoPercorrido(EstatisticaColetor estatisticaColetor) {

    // Create a simple XY chart

    JFrame frame = new JFrame();

    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();

    Map<Cidade, List<Estatistica>> mapformigasEstatisticas = new HashMap<Cidade, List<Estatistica>>();
    for (Estatistica e : estatisticaColetor.getEstatisticas()) {
        if (mapformigasEstatisticas.containsKey(e.getCidadeInicial())) {
            mapformigasEstatisticas.get(e.getCidadeInicial()).add(e);
        } else {/*from  w w w.  j  a  va  2s .co m*/
            List<Estatistica> lista = new ArrayList<Estatistica>();
            lista.add(e);

            mapformigasEstatisticas.put(e.getCidadeInicial(), lista);
        }
    }

    Set<Cidade> cidades = mapformigasEstatisticas.keySet();
    for (Cidade c : cidades) {
        // for (int i = 0; i < 2; i++) {
        List<Estatistica> list = (List<Estatistica>) mapformigasEstatisticas.get(c);

        XYSeries series = new XYSeries(c.getNome());
        dataset.addSeries(series);

        for (Estatistica e : list) {
            if (e.getFormigaId() == 1) {
                series.add(e.getIteracao(), e.getDistanciaPercorrida());
            }
        }
    }

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("", "Iterao", "Distancia (Km)", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    frame.getContentPane().add(new ChartPanel(chart));

    frame.setPreferredSize(new Dimension(600, 600));
    frame.setMinimumSize(new Dimension(600, 600));
    frame.setMaximumSize(new Dimension(600, 600));
    frame.setVisible(true);

    try {
        ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }
}