将JAR添加到NetBeans项目(答案似乎不起作用)

时间:2013-11-01 15:59:59

标签: netbeans jar

我正在尝试将JAR添加到NetBeans项目中。

我右键单击了Libraries,然后选择了Add JAR / Folder并选择了JAR,但无法识别导入。

我知道导入在那些JAR中,因为它在Eclipse中有效。

例如,import语句

import org.jfree.chart.ChartFactory;  

带有红色下划线,并显示以下错误消息:

cannot find symbol
  symbol:   class ChartFactory
  location: package org.jfree.chart
----
(Alt-Enter shows hints)

编辑:

我一直在使用NetBeans 7.3.1和JDK 7 u 25(64位)。

包含我收到上述错误的项目的zip文件(希望)可在此处获取:https://app.promobucket.com/the-church/spine-panel/a-sample-collection-1/splinepanel

代码在这里:

package splinepanel;

import java.awt.*;       // Using AWT containers and components
import javax.swing.*;    // Using Swing components and containers
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.ChartPanel;

/**
 *
 * @author User
 */
public class SplinePanel{

    public JPanel createContentPane(){

        JPanel panel = new JPanel();

        panel.setLayout(new BorderLayout());

        XYSeries series = new XYSeries("MyGraph");

        series.add(0, 1);
        series.add(1, 2);
        series.add(2, 5);
        series.add(7, 8);
        series.add(9, 10);

        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series);

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

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

        panel.add(chartPanel);

        panel.setOpaque(true); 
        return panel;  
    }

    private static void createAndShowGUI() {

        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame("[=] There's a JPanel in here! [=]");

        //Create and set up the content pane.
        SplinePanel demo = new SplinePanel();
        frame.setContentPane(demo.createContentPane());

        // The other bits and pieces that make our program a bit more stable.
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(1300, 650);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}  

编辑2:

该项目现已在此处提供:

https://github.com/bluesh34/SplinePanel/

1 个答案:

答案 0 :(得分:0)

使用罐子的绝对路径似乎不正确。 enter image description here

提案:

  1. 在项目中创建一个lib文件夹
  2. 将所有必需的jar复制到此lib文件夹
  3. 从项目属性中删除所有错误的已注册的库
  4. 重新添加所有的罐子