diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/standalone/SwingDemo.java b/xchart-demo/src/main/java/com/xeiam/xchart/standalone/SwingDemo.java new file mode 100644 index 0000000000000000000000000000000000000000..3de2b1de06cc0731222da67bc4615f23eae9c66f --- /dev/null +++ b/xchart-demo/src/main/java/com/xeiam/xchart/standalone/SwingDemo.java @@ -0,0 +1,62 @@ +/** + * Copyright 2011 - 2014 Xeiam LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.xeiam.xchart.standalone; + +import javax.swing.JFrame; +import javax.swing.JPanel; + +import com.xeiam.xchart.XChartPanel; +import com.xeiam.xchart.demo.charts.area.AreaChart01; + +/** + * Class showing how to integrate a chart into a Swing JFrame + * + * @author timmolter + */ +public class SwingDemo extends JPanel { + + /** + * Create the GUI and show it. For thread safety, this method should be invoked from the event dispatch thread. + */ + private static void createAndShowGUI() { + + // Create and set up the window. + JFrame frame = new JFrame("XChart Swing Demo"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + // Add content to the window. + JPanel chartPanel = new XChartPanel(new AreaChart01().getChart()); + frame.add(chartPanel); + + // Display the window. + frame.pack(); + frame.setVisible(true); + } + + public static void main(String[] args) { + + // Schedule a job for the event dispatch thread: + // creating and showing this application's GUI. + javax.swing.SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + createAndShowGUI(); + } + }); + } +}