Example usage for javax.swing JFrame validate

List of usage examples for javax.swing JFrame validate

Introduction

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

Prototype

public void validate() 

Source Link

Document

Validates this container and all of its subcomponents.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new PopupMenu());
    frame.validate();
    frame.pack();/*from w ww.  j  av a  2  s.c  o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new Main());
    frame.validate();
    frame.pack();/* ww w . j a  v  a  2  s .  c  o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new Main());
    frame.validate();
    frame.pack();//w w  w  .j  av a2  s .c  o  m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    DefaultTableModel model = new DefaultTableModel(null, new String[] { "CheckMe", "Value" }) {
        public Class getColumnClass(int c) {
            switch (c) {
            case 0:
                return Boolean.class;
            default:
                return String.class;
            }/* ww w.  j  ava2s  .c  o m*/
        }
    };
    JTable table = new JTable(model);
    JFrame frame = new JFrame("CheckBox Test");
    frame.add(table);
    model.addRow(new Object[] { true, "This is true" });
    model.addRow(new Object[] { false, "This is false" });
    frame.pack();
    frame.validate();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:visualize.Visualize.java

public static void main(String[] args) throws NotEnoughDataPointsException, IllDefinedDataPointsException {
    XYSeries seriesQ = new XYSeries("quadratic");
    XYSeries seriesL = new XYSeries("linear");
    XYSeries seriesI = new XYSeries("intepolated");

    final ArrayList<Point> pointsQ = new ArrayList<Point>();

    for (double x = -5.0; x <= 5.0; x = x + 0.5)
        pointsQ.add(new Point(new double[] { x, 2.0 * x * x * x - 10 * x * x }));

    final LinearFunction fl = new LinearFunction();
    final HigherOrderPolynomialFunction fq = new HigherOrderPolynomialFunction(3);
    final InterpolatedPolynomial<LinearFunction, HigherOrderPolynomialFunction> fi = new InterpolatedPolynomial<LinearFunction, HigherOrderPolynomialFunction>(
            new LinearFunction(), fq.copy(), 0.5);

    fl.fitFunction(pointsQ);/*ww  w .j a va 2 s .  c o  m*/
    fq.fitFunction(pointsQ);
    fi.fitFunction(pointsQ);

    System.out.println(fl);
    System.out.println(fq);
    System.out.println(fi.interpolatedFunction);

    for (double x = -5.0; x <= 5.0; x = x + 0.5) {
        seriesQ.add(x, fq.predict(x));
        seriesL.add(x, fl.predict(x));
        seriesI.add(x, fi.predict(x));
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(seriesQ);
    dataset.addSeries(seriesL);
    dataset.addSeries(seriesI);

    JFreeChart chart = ChartFactory.createXYLineChart("XY Chart", "x-axis", "y-axis", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    final XYPlot plot = chart.getXYPlot();
    final XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, new Color(0, 0, 255));
    renderer.setSeriesStroke(0, new BasicStroke(0.5f));
    renderer.setSeriesPaint(1, new Color(255, 0, 0));
    renderer.setSeriesStroke(1, new BasicStroke(0.5f));
    renderer.setSeriesPaint(2, new Color(0, 200, 40));
    renderer.setSeriesStroke(2, new BasicStroke(1.5f));

    //chart.getXYPlot().setRenderer(new XYSplineRenderer(100));

    JPanel panel = new JPanel();
    ChartPanel chartPanel = new ChartPanel(chart);
    panel.add(chartPanel);

    JFrame frame = new JFrame();
    frame.setContentPane(panel);
    frame.validate();
    Dimension d = new Dimension(800, 500);
    frame.setSize(d);

    frame.setVisible(true);

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println("starting");

    for (int lambda = 0; lambda <= 100; ++lambda) {
        fi.setLambda(lambda / 100.0);
        fi.fitFunction(pointsQ);
        System.out.println(fi.interpolatedFunction);

        dataset.getSeries(2).clear();
        for (double x = -5.0; x <= 5.0; x = x + 0.5)
            seriesI.add(x, fi.predict(x));

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //   makeScreenshot( lambda );
    }

}

From source file:ResizeSplit.java

public static void main(String args[]) {
    String title = "Resize Split";

    final JFrame vFrame = new JFrame(title);
    vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton topButton = new JButton("Top");
    JButton bottomButton = new JButton("Bottom");
    final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(topButton);
    splitPane.setBottomComponent(bottomButton);
    ActionListener oneActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            splitPane.setResizeWeight(1.0);
            vFrame.setSize(300, 250);//from  w w w  . j  a v  a 2s . c  o m
            vFrame.validate();
        }
    };
    bottomButton.addActionListener(oneActionListener);

    ActionListener anotherActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            splitPane.setResizeWeight(0.5);
            vFrame.setSize(300, 250);
            vFrame.validate();
        }
    };
    topButton.addActionListener(anotherActionListener);
    vFrame.getContentPane().add(splitPane, BorderLayout.CENTER);
    vFrame.setSize(300, 150);
    vFrame.setVisible(true);

}

From source file:Main.java

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

    JPanel gui = new JPanel(new BorderLayout(5, 5));

    JPanel plafComponents = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 3));
    plafComponents.setBorder(new TitledBorder("FlowLayout(FlowLayout.RIGHT, 3,3)"));

    UIManager.LookAndFeelInfo[] plafInfos = UIManager.getInstalledLookAndFeels();
    String[] plafNames = new String[plafInfos.length];
    for (int ii = 0; ii < plafInfos.length; ii++) {
        plafNames[ii] = plafInfos[ii].getName();
    }/*from  w  w  w . j  a v a 2 s  . c  om*/
    JComboBox plafChooser = new JComboBox(plafNames);
    plafComponents.add(plafChooser);

    JCheckBox pack = new JCheckBox("Pack on PLAF change", true);
    plafComponents.add(pack);

    plafChooser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int index = plafChooser.getSelectedIndex();
            try {
                UIManager.setLookAndFeel(plafInfos[index].getClassName());
                SwingUtilities.updateComponentTreeUI(frame);
                if (pack.isSelected()) {
                    frame.pack();
                    frame.setMinimumSize(frame.getSize());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    gui.add(plafComponents, BorderLayout.NORTH);

    JPanel dynamicLabels = new JPanel(new BorderLayout(4, 4));
    dynamicLabels.setBorder(new TitledBorder("BorderLayout(4,4)"));
    gui.add(dynamicLabels, BorderLayout.WEST);

    final JPanel labels = new JPanel(new GridLayout(0, 2, 3, 3));
    labels.setBorder(new TitledBorder("GridLayout(0,2,3,3)"));

    JButton addNew = new JButton("Add Another Label");
    dynamicLabels.add(addNew, BorderLayout.NORTH);
    addNew.addActionListener(new ActionListener() {

        private int labelCount = 0;

        public void actionPerformed(ActionEvent ae) {
            labels.add(new JLabel("Label " + ++labelCount));
            frame.validate();
        }
    });

    dynamicLabels.add(new JScrollPane(labels), BorderLayout.CENTER);

    String[] header = { "Name", "Value" };
    String[] a = new String[0];
    String[] names = System.getProperties().stringPropertyNames().toArray(a);
    String[][] data = new String[names.length][2];
    for (int ii = 0; ii < names.length; ii++) {
        data[ii][0] = names[ii];
        data[ii][1] = System.getProperty(names[ii]);
    }
    DefaultTableModel model = new DefaultTableModel(data, header);
    JTable table = new JTable(model);

    JScrollPane tableScroll = new JScrollPane(table);
    Dimension tablePreferred = tableScroll.getPreferredSize();
    tableScroll.setPreferredSize(new Dimension(tablePreferred.width, tablePreferred.height / 3));

    JPanel imagePanel = new JPanel(new GridBagLayout());
    JLabel imageLabel = new JLabel("test");
    imagePanel.add(imageLabel, null);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableScroll, new JScrollPane(imagePanel));
    gui.add(splitPane, BorderLayout.CENTER);

    frame.setContentPane(gui);
    frame.pack();
    frame.setVisible(true);
}

From source file:ScalingMethods.java

private static void createAndShowGUI() {
    JFrame f = new JFrame("ScalingMethods");
    f.setLayout(new BorderLayout());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ScalingMethods test = new ScalingMethods();
    f.add(test);/*from  ww  w .j  a  v a2 s.  com*/
    f.validate();
    f.pack();
    f.setVisible(true);
}

From source file:DataBufferGrabber.java

private static void createAndShowGUI() {
    JFrame f = new JFrame("DataBufferGrabber");
    f.getContentPane().setLayout(new FlowLayout());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(100, 100);//from w  w w.j  a  va2 s  .c  o m
    f.add(new DataBufferGrabber());
    f.validate();
    f.pack();
    f.setVisible(true);
}

From source file:beadAnalyzer.DrawPoints.java

public static JFrame display(final JFreeChart chart, final Dimension d) {
    final JPanel panel = new JPanel();
    final ChartPanel chartPanel = new ChartPanel(chart, d.width - 10, d.height - 35,
            ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT,
            ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT,
            ChartPanel.DEFAULT_BUFFER_USED, true, // properties
            true, // save
            true, // print
            true, // zoom
            true // tooltips
    );/*from  ww w . j a va 2  s  . c om*/
    panel.add(chartPanel);

    final JFrame frame = new JFrame();
    frame.setContentPane(panel);
    frame.validate();
    frame.setSize(d);

    frame.setVisible(true);
    return frame;
}