`
soleegn
  • 浏览: 152096 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论
阅读更多
    好像从1.03开始Jfc就已经提供了在SWT中使用JFC的专用包和类,只是没有人写这些东西而已~今天我就贴一些Demo,以后再也不用SWT_AWT了~
  1/**//* ===========================================================
  2 * JFreeChart : a free chart library for the Java(tm) platform
  3 * ===========================================================
  4 *
  5 * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
  6 *
  7 * Project Info:  http://www.jfree.org/jfreechart/index.html
  8 *
  9 * This library is free software; you can redistribute it and/or modify it 
 10 * under the terms of the GNU Lesser General Public License as published by 
 11 * the Free Software Foundation; either version 2.1 of the License, or 
 12 * (at your option) any later version.
 13 *
 14 * This library is distributed in the hope that it will be useful, but 
 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 17 * License for more details.
 18 *
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 22 * USA.  
 23 *
 24 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 25 * in the United States and other countries.]
 26 *
 27 * ---------------------
 28 * SWTBarChartDemo1.java
 29 * ---------------------
 30 * (C) Copyright 2006, 2007, by Object Refinery Limited and Contributors.
 31 *
 32 * Original Author:  David Gilbert (for Object Refinery Limited);
 33 * Contributor(s):
 34 *
 35 * Changes
 36 * -------
 37 * 23-Aug-2006 : New class (DG);
 38 * 
 39 */

 40
 41package org.jfree.experimental.chart.swt.demo;
 42
 43import java.awt.Color;
 44
 45import org.eclipse.swt.SWT;
 46import org.eclipse.swt.layout.FillLayout;
 47import org.eclipse.swt.widgets.Display;
 48import org.eclipse.swt.widgets.Shell;
 49import org.jfree.chart.ChartFactory;
 50import org.jfree.chart.JFreeChart;
 51import org.jfree.chart.axis.CategoryAxis;
 52import org.jfree.chart.axis.CategoryLabelPositions;
 53import org.jfree.chart.axis.NumberAxis;
 54import org.jfree.chart.plot.CategoryPlot;
 55import org.jfree.chart.plot.PlotOrientation;
 56import org.jfree.chart.renderer.category.BarRenderer;
 57import org.jfree.data.category.CategoryDataset;
 58import org.jfree.data.category.DefaultCategoryDataset;
 59import org.jfree.experimental.chart.swt.ChartComposite;
 60
 61/** *//**
 62 * An SWT demo.
 63 */

 64public class SWTBarChartDemo1 {
 65    
 66    /** *//**
 67     * Returns a sample dataset.
 68     * 
 69     * @return The dataset.
 70     */

 71    private static CategoryDataset createDataset() {
 72        
 73        // row keys
 74        String series1 = "First";
 75        String series2 = "Second";
 76        String series3 = "Third";
 77
 78        // column keys
 79        String category1 = "Category 1";
 80        String category2 = "Category 2";
 81        String category3 = "Category 3";
 82        String category4 = "Category 4";
 83        String category5 = "Category 5";
 84
 85        // create the dataset
 86        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
 87
 88        dataset.addValue(1.0, series1, category1);
 89        dataset.addValue(4.0, series1, category2);
 90        dataset.addValue(3.0, series1, category3);
 91        dataset.addValue(5.0, series1, category4);
 92        dataset.addValue(5.0, series1, category5);
 93
 94        dataset.addValue(5.0, series2, category1);
 95        dataset.addValue(7.0, series2, category2);
 96        dataset.addValue(6.0, series2, category3);
 97        dataset.addValue(8.0, series2, category4);
 98        dataset.addValue(4.0, series2, category5);
 99
100        dataset.addValue(4.0, series3, category1);
101        dataset.addValue(3.0, series3, category2);
102        dataset.addValue(2.0, series3, category3);
103        dataset.addValue(3.0, series3, category4);
104        dataset.addValue(6.0, series3, category5);
105        
106        return dataset;
107        
108    }

109    
110    /** *//**
111     * Creates a sample chart.
112     * 
113     * @param dataset  the dataset.
114     * 
115     * @return The chart.
116     */

117    private static JFreeChart createChart(CategoryDataset dataset) {
118        
119        // create the chart
120        JFreeChart chart = ChartFactory.createBarChart(
121            "Bar Chart Demo",         // chart title
122            "Category",               // domain axis label
123            "Value",                  // range axis label
124            dataset,                  // data
125            PlotOrientation.VERTICAL, // orientation
126            true,                     // include legend
127            true,                     // tooltips?
128            false                     // URLs?
129        );
130
131        // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART
132
133        // set the background color for the chart
134        chart.setBackgroundPaint(Color.white);
135
136        // get a reference to the plot for further customisation
137        CategoryPlot plot = (CategoryPlot) chart.getPlot();
138        plot.setBackgroundPaint(Color.lightGray);
139        plot.setDomainGridlinePaint(Color.white);
140        plot.setDomainGridlinesVisible(true);
141        plot.setRangeGridlinePaint(Color.white);
142
143        // set the range axis to display integers only
144        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
145        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
146
147        // disable bar outlines
148        BarRenderer renderer = (BarRenderer) plot.getRenderer();
149        renderer.setDrawBarOutline(false);
150
151        CategoryAxis domainAxis = plot.getDomainAxis();
152        domainAxis.setCategoryLabelPositions(
153            CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
154        );
155        // OPTIONAL CUSTOMISATION COMPLETED.
156        
157        return chart;
158        
159    }

160    
161    /** *//**
162     * Starting point for the demonstration application.
163     *
164     * @param args  ignored.
165     */

166    public static void main( String[] args ) 
167    {
168        JFreeChart chart = createChart(createDataset());
169        Display display = new Display();
170        Shell shell = new Shell(display);
171        shell.setSize(600300);
172        shell.setLayout(new FillLayout());
173        shell.setText("Test for jfreechart running with SWT");
174        final ChartComposite frame = new ChartComposite(shell, SWT.NONE, chart,
175                true);
176        frame.pack();
177        shell.open();
178        while (!shell.isDisposed()) {
179            if (!display.readAndDispatch())
180                display.sleep();
181        }

182
分享到:
评论
1 楼 yjp 2010-12-02  
效果丢失了,也好不了多少

相关推荐

    swt_awt桥接 swt_awt桥接

    今天遇到一个问题,就是要在一个Eclipse插件里显示JFreeChart的图形,因为后者是基于Java2D的,要把图形显示在SWT应用程序里需要利用SWT-AWT桥接器来实现,虽说桥接的方式多半会伴随着性能下降,但总归是一个解决...

    SWT疑难点解答,帮助新手朋友

    以上就是SWT中一些常见的疑难点解答,包括Button的样式、Text的使用、Table的操作以及在SWT中显示AWT/Swing对象的方法。理解并掌握这些知识点将有助于提升在Eclipse环境下使用SWT开发GUI应用的能力。

    jfreechart-1.0.4.jar jfreechart-1.0.4-swt.jar

    用JFreeChart实现java报表开发(1) 作者:zuoxianghui 来源:blog 整理日期:2007-8-17 jfreechart,到http://www.jfree.org/下载最新的。 一、在web.xml文件中添加: <servlet-name>DisplayChart ...

    JFreeChart资源文件

    - **SWT应用**:在Eclipse SWT环境中,JFreeChart也可以通过 SWT/AWT 桥接来创建和显示图表。 **4. 扩展和社区支持** JFreeChart拥有活跃的开发者社区,用户可以在其官方网站上找到详细的API文档、示例代码、用户...

    jfreechart-1.0.13 jar包

    5. **servlet.jar**:可能用于服务器端集成,使得 JFreeChart 可以在 Web 应用中使用。 6. **jfreechart-1.0.13-swt.jar** 和 **swtgraphics2d.jar**:这两个 JAR 文件与 SWT(标准小部件工具包)相关,允许 ...

    JFreechart

    在给定的部分内容中,展示了一个简单的使用 JFreeChart 绘制柱状图的例子。下面我们将对这段代码进行详细的解析: ##### 1. 导入必要的类 ```java import java.awt.Color; import java.awt.Component; import javax...

    图表滚动条

    在本场景中,我们关注的是"scrollbar"与"jfreechart"的结合,特别是如何在Java环境中使用SWT(Standard Widget Toolkit)库来实现图表的滚动条功能。 JFreeChart是一个强大的Java图表库,它提供了各种图表类型,如...

Global site tag (gtag.js) - Google Analytics