Example usage for javax.swing JFrame setContentPane

List of usage examples for javax.swing JFrame setContentPane

Introduction

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

Prototype

@BeanProperty(bound = false, hidden = true, description = "The client area of the frame where child components are normally inserted.")
public void setContentPane(Container contentPane) 

Source Link

Document

Sets the contentPane property.

Usage

From source file:charts.Chart.java

public static Vector MultipleStepChartOverlayedMA(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());
    rangeAxis.setAutoRange(true);/*  ww  w  .j  a va  2s. c  om*/
    CombinedDomainCategoryPlot parent = new CombinedDomainCategoryPlot(new CategoryAxis(x_axis_label));
    DefaultCategoryItemRenderer renderer0 = new DefaultCategoryItemRenderer();
    renderer0.setBaseStroke(new BasicStroke(2.0f));
    renderer0.setBaseSeriesVisibleInLegend(showlegend);
    renderer0.setSeriesPaint(0, Color.RED);//sinal original
    renderer0.setShapesVisible(false);
    CategoryPlot subplot = new CategoryPlot(datasets[0], domainAxis, rangeAxis, renderer0);
    subplot.setBackgroundPaint(Color.white);
    subplot.setRangeGridlinePaint(Color.black);
    subplot.setDomainGridlinesVisible(true);
    parent.add(subplot);

    CategoryAxis domainAxis1 = new CategoryAxis(x_axis_label);
    ValueAxis rangeAxis1 = new NumberAxis(y_axis_label);
    rangeAxis1.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    rangeAxis1.setAutoRange(true);

    CategoryItemRenderer renderer1 = new CategoryStepRenderer(true);
    renderer1.setBaseStroke(new BasicStroke(2.0f));
    renderer1.setBaseSeriesVisibleInLegend(showlegend);
    renderer1.setSeriesPaint(0, Color.BLUE);//sinal quantizado
    CategoryPlot subplot1 = new CategoryPlot(datasets[1], domainAxis1, rangeAxis1, renderer1);
    //subplot.setDataset(1, datasets[1]);
    //subplot.setRenderer(1, renderer1);
    parent.add(subplot1);

    DefaultCategoryItemRenderer renderer2 = new DefaultCategoryItemRenderer();
    renderer2.setBaseStroke(new BasicStroke(2.0f));
    renderer2.setBaseSeriesVisibleInLegend(showlegend);
    renderer2.setShapesVisible(false);
    renderer2.setSeriesPaint(0, Color.BLACK);//sinal normalizado
    subplot1.setDataset(1, datasets[2]);
    subplot1.setRenderer(1, renderer2);

    for (int i = 3; i < datasets.length; i++) {
        DefaultCategoryItemRenderer renderer3 = new DefaultCategoryItemRenderer();
        renderer3.setBaseStroke(new BasicStroke(2.0f));
        renderer3.setBaseSeriesVisibleInLegend(showlegend);
        renderer3.setShapesVisible(false);
        renderer3.setSeriesPaint(0, Color.LIGHT_GRAY);//limiares utilizados para quantizacao.
        subplot1.setDataset(i - 1, datasets[i]);
        subplot1.setRenderer(i - 1, renderer3);
    }

    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    JPanel retorno = new ChartPanel(jfreechart);
    retorno.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    JFrame chartwindow = new JFrame(title);
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(showchart);
    Vector res = new Vector();
    res.add(0, jfreechart);
    res.add(1, chartwindow);
    res.add(2, retorno);
    return res;
}

From source file:misc.TextBatchPrintingDemo.java

/**
 * Create and display the main application frame.
 *//*from w  w w  . jav a  2s. co  m*/
void createAndShowGUI() {
    messageArea = new JLabel(defaultMessage);

    selectedPages = new JList(new DefaultListModel());
    selectedPages.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectedPages.addListSelectionListener(this);

    setPage(homePage);

    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(pageItem),
            new JScrollPane(selectedPages));

    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);

    /** Menu item and keyboard shortcuts for the "add page" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Add Page") {
        public void actionPerformed(ActionEvent e) {
            DefaultListModel pages = (DefaultListModel) selectedPages.getModel();
            pages.addElement(pageItem);
            selectedPages.setSelectedIndex(pages.getSize() - 1);
        }
    }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "print selected" command.*/
    fileMenu.add(createMenuItem(new AbstractAction("Print Selected") {
        public void actionPerformed(ActionEvent e) {
            printSelectedPages();
        }
    }, KeyEvent.VK_P, KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "clear selected" command.*/
    fileMenu.add(createMenuItem(new AbstractAction("Clear Selected") {
        public void actionPerformed(ActionEvent e) {
            DefaultListModel pages = (DefaultListModel) selectedPages.getModel();
            pages.removeAllElements();
        }
    }, KeyEvent.VK_C, KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK)));

    fileMenu.addSeparator();

    /** Menu item and keyboard shortcuts for the "home page" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Home Page") {
        public void actionPerformed(ActionEvent e) {
            setPage(homePage);
        }
    }, KeyEvent.VK_H, KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "quit" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Quit") {
        public void actionPerformed(ActionEvent e) {
            for (Window w : Window.getWindows()) {
                w.dispose();
            }
        }
    }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK)));

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    contentPane.add(pane);
    contentPane.add(messageArea);

    JFrame frame = new JFrame("Text Batch Printing Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(menuBar);
    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    if (printService == null) {
        // Actual printing is not possible, issue a warning message.
        JOptionPane.showMessageDialog(frame, "No default print service", "Print Service Alert",
                JOptionPane.WARNING_MESSAGE);
    }
}

From source file:edu.ku.brc.specify.tasks.StatsTrackerTask.java

@Override
protected void showClosingFrame() {
    if (hasChanged) {
        ImageIcon img = IconManager.getIcon("SpecifySplash");

        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,150px", "f:p:g,2px,p"));
        pb.setDefaultDialogBorder();/*from   ww  w  .  j  a  v  a  2s  . c  o m*/

        JLabel lbl = new JLabel(img);
        pb.add(lbl, cc.xyw(1, 1, 2));
        lbl = UIHelper.createI18NLabel("SPECIFY_SHUTDOWN", SwingConstants.CENTER);
        lbl.setFont(lbl.getFont().deriveFont(18.0f));
        pb.add(lbl, cc.xy(1, 3));

        progress = new JProgressBar(0, 100);
        pb.add(progress, cc.xy(2, 3));

        JFrame frame = new JFrame();
        frame.setUndecorated(true);
        frame.setContentPane(pb.getPanel());
        frame.pack();
        UIHelper.centerAndShow(frame);
    }
}

From source file:com.wwidesigner.modelling.PlotPlayingRanges.java

/**
 * Display the graph generated in buildGraph().
 * @param exitOnClose - If true, the application will exit when the user closes the plot window.
 *//*from   ww w .j a v  a2  s  . c  om*/
public void plotGraph(final boolean exitOnClose) {
    final Chart graph = chart;
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new JFrame("Impedance Pattern for " + mName);
            if (exitOnClose) {
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
            frame.setSize(800, 600);

            frame.setContentPane(graph);
            frame.setVisible(true);
        }
    });
}

From source file:org.keyboardplaying.xtt.ui.UIController.java

private Window makeWindow(String titleKey, String iconKey, Container content) {
    /* The basics. */
    JFrame window = new I14edJFrame(i18n, titleKey);
    window.setIconImages(images.getImages(iconKey));
    /* Make sure thread is ended when window is closed. */
    window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    /* Add content and adapt size to fit the content. */
    window.setContentPane(content);
    window.pack();/*from w ww. jav  a  2 s.  co  m*/
    // Center on screen
    window.setLocationRelativeTo(null);

    return window;
}

From source file:umontreal.iro.lecuyer.charts.BoxChart.java

/**
 * Displays chart on the screen using Swing.
 *    This method creates an application containing a chart panel displaying
 *    the chart.  The created frame is positioned on-screen, and displayed before
 *    it is returned. The circle represents the mean, the dark line inside the box
 *    is the median, the box limits are the first and third quartiles,
 *    the lower whisker (the lower line outside the box) is the first decile,
 *    and the upper whisker is the ninth decile. The outliers, if any, are
 *    represented by empty circles, or arrows if outside the range bounds.
 * //from   ww w .java  2  s.co m
 * @param width frame width.
 * 
 *    @param height frame height.
 * 
 *    @return frame containing the chart.;
 * 
 */
public JFrame view(int width, int height) {
    JFrame myFrame;
    if (chart.getTitle() != null)
        myFrame = new JFrame("BoxChart from SSJ : " + chart.getTitle().getText());
    else
        myFrame = new JFrame("BoxChart from SSJ");
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    myFrame.setContentPane(chartPanel);
    myFrame.pack();
    myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    myFrame.setLocationRelativeTo(null);
    myFrame.setVisible(true);
    return myFrame;
}

From source file:adapters.BoxChartAdapter.java

/**
 * Modified Method: set visible to be false
 *
 * Displays chart on the screen using Swing.
 *    This method creates an application containing a chart panel displaying
 *    the chart.  The created frame is positioned on-screen, and displayed before
 *    it is returned. The circle represents the mean, the dark line inside the box
 *    is the median, the box limits are the first and third quartiles,
 *    the lower whisker (the lower line outside the box) is the first decile,
 *    and the upper whisker is the ninth decile. The outliers, if any, are
 *    represented by empty circles, or arrows if outside the range bounds.
 *
 * @param width frame width.//from w w  w  . j av a2s .co m
 *
 *    @param height frame height.
 *
 *    @return frame containing the chart.;
 *
 */
public JFrame view(int width, int height) {
    JFrame myFrame;
    if (chart.getTitle() != null)
        myFrame = new JFrame("BoxChart: " + chart.getTitle().getText());
    else
        myFrame = new JFrame("BoxChart");
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    myFrame.setContentPane(chartPanel);
    myFrame.pack();
    myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    myFrame.setLocationRelativeTo(null);
    // myFrame.setVisible (true);
    return myFrame;
}

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 ww. j  av  a2s  .co  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 void PontosXY() {

    XYSeries series2 = new XYSeries("Max Value");
    series2.add(30.0, 15.0);/*ww  w. j  a  va  2s.co  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);
}

From source file:com.diversityarrays.kdxplore.curate.fieldview.OverviewDialog.java

@SuppressWarnings("unchecked")
public OverviewDialog(Window window, String title,

        @SuppressWarnings("rawtypes") ComboBoxModel comboBoxModel, CurationData curationData,
        Transformer<TraitInstance, String> tiNameProvider, OverviewInfoProvider overviewInfoProvider,
        FieldViewSelectionModel fvsm, FieldLayoutTableModel fltm, CurationTableModel ctm) {
    super(window, title, ModalityType.MODELESS);

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    setAlwaysOnTop(true);//  w w w  .j  a  v a  2 s  . c  o  m

    this.fieldViewSelectionModel = fvsm;

    @SuppressWarnings({ "rawtypes" })
    JComboBox activeTiCombo = new JComboBox(comboBoxModel);
    TraitInstanceCellRenderer tiCellRenderer = new TraitInstanceCellRenderer(
            curationData.getTraitColorProvider(), tiNameProvider);
    activeTiCombo.setRenderer(tiCellRenderer);

    JLabel infoLabel = new JLabel(" ");
    infoLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));

    final JFrame[] helpDialog = new JFrame[1];
    Action helpAction = new AbstractAction("?") {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (helpDialog[0] != null) {
                GuiUtil.restoreFrame(helpDialog[0]);
            } else {
                JFrame f = new JFrame("Overview Help");
                helpDialog[0] = f;
                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                f.setAlwaysOnTop(true);
                f.setLocationRelativeTo(overview);
                String html = Overview.getOverviewHelpHtml();
                JLabel label = new JLabel(html);
                label.setBorder(new EmptyBorder(0, 10, 0, 10));
                f.setContentPane(label);
                f.pack();
                f.setVisible(true);
            }
        }
    };

    //        Window window = GuiUtil.getOwnerWindow(FieldLayoutViewPanel.this);
    if (window != null) {
        if (window instanceof JFrame) {
            System.out.println("Found window: " + ((JFrame) window).getTitle());
        }
        window.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                window.removeWindowListener(this);
                if (helpDialog[0] != null) {
                    helpDialog[0].dispose();
                }
            }
        });
    }

    KDClientUtils.initAction(ImageId.HELP_24, helpAction, "Help for Overview");
    Box top = Box.createHorizontalBox();
    top.add(activeTiCombo);
    top.add(new JButton(helpAction));

    overview = new Overview(overviewInfoProvider, fltm, curationData, ctm, infoLabel);
    overview.setActiveTraitInstance(fvsm.getActiveTraitInstance(true));
    Container cp = getContentPane();

    cp.add(top, BorderLayout.NORTH);
    //      cp.add(traitLabel, BorderLayout.NORTH);
    cp.add(infoLabel, BorderLayout.SOUTH);
    cp.add(overview, BorderLayout.CENTER);

    pack();
    //      setResizable(false);

    //      setLocationRelativeTo(showOverviewButton);
    // DEFAULT POSITION is "out of the way"
    setVisible(true);

    this.fieldViewSelectionModel.addListSelectionListener(listSelectionListener);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            toFront();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            fieldViewSelectionModel.removeListSelectionListener(listSelectionListener);
            removeWindowListener(this);
        }
    });
}