Example usage for javax.swing JFrame show

List of usage examples for javax.swing JFrame show

Introduction

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

Prototype

@Deprecated
public void show() 

Source Link

Document

Makes the Window visible.

Usage

From source file:SimpleClient.java

public static void main(String argv[]) {
    boolean usage = false;

    for (int optind = 0; optind < argv.length; optind++) {
        if (argv[optind].equals("-L")) {
            url.addElement(argv[++optind]);
        } else if (argv[optind].startsWith("-")) {
            usage = true;/*from   ww  w.j a v a  2 s  .c o  m*/
            break;
        } else {
            usage = true;
            break;
        }
    }

    if (usage || url.size() == 0) {
        System.out.println("Usage: SimpleClient -L url");
        System.out.println("   where url is protocol://username:password@hostname/");
        System.exit(1);
    }

    try {
        // Set up our Mailcap entries.  This will allow the JAF
        // to locate our viewers.
        File capfile = new File("simple.mailcap");
        if (!capfile.isFile()) {
            System.out.println("Cannot locate the \"simple.mailcap\" file.");
            System.exit(1);
        }

        CommandMap.setDefaultCommandMap(new MailcapCommandMap(new FileInputStream(capfile)));

        JFrame frame = new JFrame("Simple JavaMail Client");
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        //frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        // Get a Store object
        SimpleAuthenticator auth = new SimpleAuthenticator(frame);
        Session session = Session.getDefaultInstance(System.getProperties(), auth);
        //session.setDebug(true);

        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");

        // create a node for each store we have
        for (Enumeration e = url.elements(); e.hasMoreElements();) {
            String urlstring = (String) e.nextElement();
            URLName urln = new URLName(urlstring);
            Store store = session.getStore(urln);

            StoreTreeNode storenode = new StoreTreeNode(store);
            root.add(storenode);
        }

        DefaultTreeModel treeModel = new DefaultTreeModel(root);
        JTree tree = new JTree(treeModel);
        tree.addTreeSelectionListener(new TreePress());

        /* Put the Tree in a scroller. */
        JScrollPane sp = new JScrollPane();
        sp.setPreferredSize(new Dimension(250, 300));
        sp.getViewport().add(tree);

        /* Create a double buffered JPanel */
        JPanel sv = new JPanel(new BorderLayout());
        sv.add("Center", sp);

        fv = new FolderViewer(null);

        JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sv, fv);
        jsp.setOneTouchExpandable(true);
        mv = new MessageViewer();
        JSplitPane jsp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jsp, mv);
        jsp2.setOneTouchExpandable(true);

        frame.getContentPane().add(jsp2);
        frame.pack();
        frame.show();

    } catch (Exception ex) {
        System.out.println("SimpletClient caught exception");
        ex.printStackTrace();
        System.exit(1);
    }
}

From source file:DragImage.java

public static void main(String args[]) {

    JFrame frame = new JFrame("Clip Image");
    Container contentPane = frame.getContentPane();

    final Clipboard clipboard = frame.getToolkit().getSystemClipboard();

    Icon icon = new ImageIcon("jaeger.jpg");
    final JLabel label = new JLabel(icon);
    label.setTransferHandler(new ImageSelection());

    MouseListener mouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JComponent comp = (JComponent) e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.exportAsDrag(comp, e, TransferHandler.COPY);
        }/*w  w w  . ja  v a  2 s  .  c  om*/
    };
    label.addMouseListener(mouseListener);

    JScrollPane pane = new JScrollPane(label);
    contentPane.add(pane, BorderLayout.CENTER);

    JButton copy = new JButton("Copy");
    copy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            TransferHandler handler = label.getTransferHandler();
            handler.exportToClipboard(label, clipboard, TransferHandler.COPY);
        }
    });

    JButton clear = new JButton("Clear");
    clear.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            label.setIcon(null);
        }
    });
    clear.setTransferHandler(new TransferHandler("text"));
    mouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JComponent comp = (JComponent) e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.exportAsDrag(comp, e, TransferHandler.COPY);
        }
    };
    clear.addMouseListener(mouseListener);

    JButton paste = new JButton("Paste");
    paste.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Transferable clipData = clipboard.getContents(clipboard);
            if (clipData != null) {
                if (clipData.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                    TransferHandler handler = label.getTransferHandler();
                    handler.importData(label, clipData);
                }
            }
        }
    });

    JPanel p = new JPanel();
    p.add(copy);
    p.add(clear);
    p.add(paste);
    contentPane.add(p, BorderLayout.SOUTH);

    JTextField tf = new JTextField();
    tf.setDragEnabled(true);
    contentPane.add(tf, BorderLayout.NORTH);
    frame.setSize(300, 300);
    frame.show();
}

From source file:DateTimeEditor.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);//from  w ww  .ja  v  a2s  . c  o  m
        }
    });

    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(new EmptyBorder(5, 5, 5, 5));
    frame.setContentPane(panel);
    final DateTimeEditor field = new DateTimeEditor(DateTimeEditor.DATETIME, DateFormat.FULL);
    panel.add(field, "North");

    JPanel buttonBox = new JPanel(new GridLayout(2, 2));
    JButton showDateButton = new JButton("Show Date");
    buttonBox.add(showDateButton);

    final JComboBox timeDateChoice = new JComboBox();
    timeDateChoice.addItem("Time");
    timeDateChoice.addItem("Date");
    timeDateChoice.addItem("Date/Time");
    timeDateChoice.setSelectedIndex(2);
    timeDateChoice.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            field.setTimeOrDateType(timeDateChoice.getSelectedIndex());
        }
    });
    buttonBox.add(timeDateChoice);

    JButton toggleButton = new JButton("Toggle Enable");
    buttonBox.add(toggleButton);
    showDateButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println(field.getDate());
        }
    });
    toggleButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            field.setEnabled(!field.isEnabled());
        }
    });
    panel.add(buttonBox, "South");

    final JComboBox lengthStyleChoice = new JComboBox();
    lengthStyleChoice.addItem("Full");
    lengthStyleChoice.addItem("Long");
    lengthStyleChoice.addItem("Medium");
    lengthStyleChoice.addItem("Short");
    lengthStyleChoice.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            field.setLengthStyle(lengthStyleChoice.getSelectedIndex());
        }
    });
    buttonBox.add(lengthStyleChoice);

    frame.pack();
    Dimension dim = frame.getToolkit().getScreenSize();
    frame.setLocation(dim.width / 2 - frame.getWidth() / 2, dim.height / 2 - frame.getHeight() / 2);
    frame.show();
}

From source file:Main.java

static public void show(Component panel) {
    JFrame frame = new JFrame();
    frame.setTitle("TestForm");
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.getContentPane().add(panel);/*from w  w w. ja  va  2s.  c  o  m*/
    frame.pack();
    frame.show();
}

From source file:org.jfree.chart.demo.SymbolicYPlotDemo.java

/**
 * Displays an XYPlot with Y symbolic data.
 * //from   w w  w .j a  v a2 s.c  o  m
 * @param frameTitle
 *           the frame title.
 * @param data
 *           the data.
 * @param chartTitle
 *           the chart title.
 * @param xAxisLabel
 *           the x-axis label.
 * @param yAxisLabel
 *           the y-axis label.
 */
private static void displayYSymbolic(final String frameTitle, final XYDataset data, final String chartTitle,
        final String xAxisLabel, final String yAxisLabel) {

    final JFreeChart chart = createYSymbolicPlot(chartTitle, xAxisLabel, yAxisLabel, data, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.green));

    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}

From source file:org.jfree.chart.demo.SymbolicXYPlotDemo.java

/**
 * Displays an XYPlot with symbolic axes.
 * /* ww  w  .  j  av  a2  s.  com*/
 * @param frameTitle
 *           the frame title.
 * @param data
 *           the dataset.
 * @param chartTitle
 *           the chart title.
 * @param xAxisLabel
 *           the x axis label.
 * @param yAxisLabel
 *           the y axis label.
 */
private static void displayXYSymbolic(final String frameTitle, final XYDataset data, final String chartTitle,
        final String xAxisLabel, final String yAxisLabel) {

    final JFreeChart chart = createXYSymbolicPlot(chartTitle, xAxisLabel, yAxisLabel, data, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.green));
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}

From source file:org.jfree.chart.demo.SymbolicYPlotDemo.java

/**
 * Displays a vertically combined symbolic plot.
 * //from  ww  w.  j av  a  2 s .c  om
 * @param frameTitle
 *           the frame title.
 * @param data1
 *           dataset 1.
 * @param data2
 *           dataset 2.
 */
private static void displayYSymbolicCombinedVertically(final String frameTitle,
        final SampleYSymbolicDataset data1, final SampleYSymbolicDataset data2) {

    final String title = "Animals Vertically Combined";
    final String xAxisLabel = "Miles";
    final String yAxisLabel = null;

    // create master dataset...
    final CombinedDataset data = new CombinedDataset();
    data.add(data1);
    data.add(data2);

    // decompose data...
    final XYDataset series0 = new SubSeriesDataset(data, 0);
    final XYDataset series1 = new SubSeriesDataset(data, 1);
    final XYDataset series2 = new SubSeriesDataset(data, 2);
    final XYDataset series3 = new SubSeriesDataset(data, 3);
    final XYDataset series4 = new SubSeriesDataset(data, 4);
    final XYDataset series5 = new SubSeriesDataset(data, 5);
    final XYDataset series6 = new SubSeriesDataset(data, 6);
    final XYDataset series7 = new SubSeriesDataset(data, 7);

    // common horizontal and vertical axes
    final ValueAxis valueAxis = new NumberAxis(xAxisLabel);
    final SymbolicAxis symbolicAxis1 = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data1).getYSymbolicValues());
    final SymbolicAxis symbolicAxis2 = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data2).getYSymbolicValues());

    // create the main plot...
    final CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(valueAxis);

    // and the sub-plots...
    final XYItemRenderer renderer0 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot0 = new XYPlot(series0, null, symbolicAxis1, renderer0);
    final XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot1 = new XYPlot(series1, null, symbolicAxis1, renderer1);
    final XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot2 = new XYPlot(series2, null, symbolicAxis1, renderer2);
    final XYItemRenderer renderer3 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot3 = new XYPlot(series3, null, symbolicAxis1, renderer3);
    final XYItemRenderer renderer4 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot4 = new XYPlot(series4, null, symbolicAxis2, renderer4);
    final XYItemRenderer renderer5 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot5 = new XYPlot(series5, null, symbolicAxis2, renderer5);
    final XYItemRenderer renderer6 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot6 = new XYPlot(series6, null, symbolicAxis2, renderer6);
    final XYItemRenderer renderer7 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot7 = new XYPlot(series7, null, symbolicAxis2, renderer7);

    // add the subplots to the main plot...
    mainPlot.add(subplot0, 1);
    mainPlot.add(subplot1, 1);
    mainPlot.add(subplot2, 1);
    mainPlot.add(subplot3, 1);
    mainPlot.add(subplot4, 1);
    mainPlot.add(subplot5, 1);
    mainPlot.add(subplot6, 1);
    mainPlot.add(subplot7, 1);

    // construct the chart...
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    // and present it in a frame...
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}

From source file:org.jfree.chart.demo.SymbolicYPlotDemo.java

/**
 * Create and display an overlaid chart.
 * /*from  ww  w.  j  av  a2 s .co  m*/
 * @param frameTitle
 *           the frame title.
 * @param data1
 *           dataset1.
 * @param data2
 *           dataset2.
 */
private static void displayYSymbolicOverlaid(final String frameTitle, final XYDataset data1,
        final XYDataset data2) {

    final String title = "Animals Overlaid";
    final String xAxisLabel = "Miles";
    final String yAxisLabel = "Animal";

    // combine the y symbolic values of the two data sets...
    final String[] combinedYSymbolicValues = SampleYSymbolicDataset.combineYSymbolicDataset((YisSymbolic) data1,
            (YisSymbolic) data2);

    // make master dataset...
    final CombinedDataset data = new CombinedDataset();
    data.add(data1);
    data.add(data2);

    // decompose data...
    final XYDataset series0 = new SubSeriesDataset(data, 0);
    final XYDataset series1 = new SubSeriesDataset(data, 1);
    final XYDataset series2 = new SubSeriesDataset(data, 2);
    final XYDataset series3 = new SubSeriesDataset(data, 3);
    final XYDataset series4 = new SubSeriesDataset(data, 4);
    final XYDataset series5 = new SubSeriesDataset(data, 5);
    final XYDataset series6 = new SubSeriesDataset(data, 6);
    final XYDataset series7 = new SubSeriesDataset(data, 7);

    // create main plot...
    final ValueAxis valueAxis = new NumberAxis(xAxisLabel);
    final SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues);
    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot plot = new XYPlot(series0, valueAxis, symbolicAxis, renderer);

    plot.setDataset(1, series1);
    final XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(1, renderer1);

    plot.setDataset(2, series2);
    final XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(2, renderer2);

    plot.setDataset(3, series3);
    final XYItemRenderer renderer3 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(3, renderer3);

    plot.setDataset(4, series4);
    final XYItemRenderer renderer4 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(4, renderer4);

    plot.setDataset(5, series5);
    final XYItemRenderer renderer5 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(5, renderer5);

    plot.setDataset(6, series6);
    final XYItemRenderer renderer6 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(6, renderer6);

    plot.setDataset(7, series7);
    final XYItemRenderer renderer7 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(7, renderer7);

    // make the chart...
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    // and present it in a frame...
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}

From source file:org.jfree.chart.demo.SymbolicXYPlotDemo.java

/**
 * Displays an overlaid XYPlot with X and Y symbolic data.
 * /*from www.  ja va2  s  .co m*/
 * @param frameTitle
 *           the frame title.
 * @param data1
 *           the dataset 1.
 * @param data2
 *           the dataset 2.
 */
private static void displayXYSymbolicOverlaid(final String frameTitle, final XYDataset data1,
        final XYDataset data2) {

    final String title = "Pollutant Overlaid";
    final String xAxisLabel = "Contamination and Type";
    final String yAxisLabel = "Pollutant";

    // combine the x symbolic values of the two data sets
    final String[] combinedXSymbolicValues = SampleXYSymbolicDataset
            .combineXSymbolicDataset((XisSymbolic) data1, (XisSymbolic) data2);

    // combine the y symbolic values of the two data sets
    final String[] combinedYSymbolicValues = SampleXYSymbolicDataset
            .combineYSymbolicDataset((YisSymbolic) data1, (YisSymbolic) data2);

    // make master dataset...
    final CombinedDataset data = new CombinedDataset();
    data.add(data1);
    data.add(data2);

    // decompose data...
    final XYDataset series0 = new SubSeriesDataset(data, 0);
    final XYDataset series1 = new SubSeriesDataset(data, 1);

    // create overlaid plot...
    final SymbolicAxis hsymbolicAxis = new SymbolicAxis(xAxisLabel, combinedXSymbolicValues);
    final SymbolicAxis vsymbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues);

    final XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot plot = new XYPlot(series0, hsymbolicAxis, vsymbolicAxis, renderer1);

    final XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setDataset(1, series1);
    plot.setRenderer(1, renderer2);

    // make the chart...
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    // and present it in a frame...
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}

From source file:org.jfree.chart.demo.SymbolicXYPlotDemo.java

/**
 * Displays an horizontally combined XYPlot with X and Y symbolic data.
 * /* w  ww .j a  v  a2  s .co  m*/
 * @param frameTitle
 *           the frame title.
 * @param data1
 *           the dataset 1.
 * @param data2
 *           the dataset 2.
 */
private static void displayXYSymbolicCombinedHorizontally(final String frameTitle, final XYDataset data1,
        final XYDataset data2) {

    final String title = "Pollutant Horizontally Combined";
    final String x1AxisLabel = "Contamination";
    final String x2AxisLabel = "Type";
    final String yAxisLabel = "Pollutant";

    // combine the y symbolic values of the two data sets
    final String[] combinedYSymbolicValues = SampleXYSymbolicDataset
            .combineYSymbolicDataset((YisSymbolic) data1, (YisSymbolic) data2);

    // make master dataset...
    final CombinedDataset data = new CombinedDataset();
    data.add(data1);
    data.add(data2);

    // decompose data...
    final XYDataset series0 = new SubSeriesDataset(data, 0);
    final XYDataset series1 = new SubSeriesDataset(data, 1);

    JFreeChart chart = null;

    // common horizontal and vertical axes
    final SymbolicAxis hsymbolicAxis0 = new SymbolicAxis(x1AxisLabel,
            ((XisSymbolic) data1).getXSymbolicValues());
    final SymbolicAxis hsymbolicAxis1 = new SymbolicAxis(x2AxisLabel,
            ((XisSymbolic) data2).getXSymbolicValues());
    final SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues);

    // create main plot...
    final CombinedRangeXYPlot mainPlot = new CombinedRangeXYPlot(symbolicAxis);

    // add subplots...
    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot0 = new XYPlot(series0, hsymbolicAxis0, null, renderer);
    final XYPlot subplot1 = new XYPlot(series1, hsymbolicAxis1, null, renderer);
    mainPlot.add(subplot0, 1);
    mainPlot.add(subplot1, 1);

    // make the top level JFreeChart object
    chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    // and present it in a frame...
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}