我正在尝试将 JAR 添加到 NetBeans 项目中。
我右键单击库,然后选择添加 JAR/文件夹并选择 JAR,但无法识别导入。
我知道导入在那些 JAR 中,因为它在 Eclipse 中工作。
例如,导入语句
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:
该项目现在可在此处获得: