GUI components, graphs and charts . - java

Okay, so I am stumped. Does anyone know of a simple method for Java using NetBeans that will draw a graph (preferably a Pie Chart) using a paint component on the jPanel?
I have Googled, and researched and can't find a straight answer. I am still learning and this is the last component of my final for this class. I only need the method, if anyone knows a simple way to do this. It doesn't need to change as the requirement states that I only need a graphic; the program logic parses from the temp.textField. Any help or direction is greatly appreciated.
P.S. Yes, I have tried JFreeCharts.
private void jPanel1ComponentShown(java.awt.event.ComponentEvent evt) {
// Bar graph component and logic.
BorderLayout panelMapLayout = new BorderLayout();
jPanel1.setLayout(panelMapLayout);
jPanel1.add(Graph, BorderLayout.CENTER);
JFrame fr = new JFrame();
final int width = 300;
final int height = 400;
fr.setSize(width, height);
fr.setTitle("Grade Bar Graph");
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fr.setVisible(true);
String str = JOptionPane.showInputDialog("What is the String file name?");
barGraphComponent component = new barGraphComponent();
fr.setVisible(true);
}
Above is my code - only a portion, but I think this will work. Anyone have any ideas how I can add logic to it? If need be I will throw the whole code up. I do not need it to change, only display an initial set of integers; but how do I get those integers into my graph?

Use JCommon & JFreechart jars.
I hope u can go with it..!
import java.io.File;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
public class JavaApplication3 {
DefaultCategoryDataset categoryDataset;
private String YaxisXaxis = "Hospital mortality rate";
private String Xaxis[] = {"2009APR-2010MAR", "2010APR-2011MAR", "2011APR-2011NOV"};
double val[] = {1.7879989, 1.6252073, 1.5941324};
JFreeChart chart ;
public void getinput() {
}
void setinp() {
categoryDataset = new DefaultCategoryDataset();
for (int i = 0; i < val.length; i++) {
categoryDataset.setValue(val[i], YaxisXaxis, Xaxis[i]);
}
}
void drawcharts(){
chart = ChartFactory.createBarChart3D("XYZ HOSPITALS", // Title
"Year", // X-Axis label
"Number of Students",// Y-Axis label
categoryDataset, // Dataset
PlotOrientation.VERTICAL,
true, // Show legend
true,
false
);
}
void savechart()
{
String fileName="d:/sp.jpg";
try {
/**
* This utility saves the JFreeChart as a JPEG
* First Parameter: FileName
* Second Parameter: Chart To Save
* Third Parameter: Height Of Picture
* Fourth Parameter: Width Of Picture
*/
ChartUtilities.saveChartAsJPEG(new File(fileName), chart, 800, 600);
} catch (IOException e) {
System.err.println("Problem occurred creating chart.");
}
}
public static void main(String[] args) {
// TODO code application logic here
JavaApplication3 obj =new JavaApplication3();
obj.setinp();
obj.drawcharts();
obj.savechart();
}
}
Try this sample... U can get easily...

Related

Infinite JavaFX coordinate system pane

I need to write a custom pane that behaves like an infinite two-dimensional cartesian coordinate system. When first showing I want 0,0 to be in the center of the pane. The user should be able to navigate the pane by holding down the left mouse button and dragging. It needs to have the ability to zoom in and out. I also have to be able to place nodes at specific coordinates.
Of course I am aware that this is a very specific control and I am not asking anyone to give me step-by-step instructions or write it for me.
I am just new to the world of JFX custom controls and don't know how to approach this problem, especially the whole infinity thing.
This is not so difficult to achieve as you may think. Just start with a simple Pane. That already gives you the infinte coordinate system. The only difference from your requirement is that the point 0/0 is in the upper left corner and not in the middle. This can be fixed by applying a translate transform to the pane. Zooming and panning can then be achieved in a similar way by adding the corresponding mouse listeners to the Pane.
One approach is to render arbitrary content in a Canvas, as suggested here. The corresponding GraphicsContext gives you maximum control of the coordinates. As a concrete example, jfreechart renders charts using jfreechart-fx, whose ChartViewer holds a ChartCanvas that extends Canvas. Starting from this example, the variation below sets the domain axis to span an interval centered on zero after adding corresponding points to the three series. Use the mouse wheel or context menu to zoom; see this related answer for more on zooming and panning.
for (double t = -3; t <= 3; t += 0.5) {
series.add(t, Math.sin(t) + i);
}
…
xAxis.setRange(-Math.PI, Math.PI);
…
plot.setDomainPannable(true);
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.ChartEntity;
import org.jfree.chart.entity.LegendItemEntity;
import org.jfree.chart.entity.XYItemEntity;
import org.jfree.chart.fx.ChartViewer;
import org.jfree.chart.fx.interaction.ChartMouseEventFX;
import org.jfree.chart.fx.interaction.ChartMouseListenerFX;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
/**
* #see https://stackoverflow.com/a/44967809/230513
* #see https://stackoverflow.com/a/43286042/230513
*/
public class VisibleTest extends Application {
#Override
public void start(Stage stage) {
XYSeriesCollection dataset = new XYSeriesCollection();
for (int i = 0; i < 3; i++) {
XYSeries series = new XYSeries("value" + i);
for (double t = -3; t <= 3; t += 0.5) {
series.add(t, Math.sin(t) + i);
}
dataset.addSeries(series);
}
NumberAxis xAxis = new NumberAxis("domain");
xAxis.setRange(-Math.PI, Math.PI);
NumberAxis yAxis = new NumberAxis("range");
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
JFreeChart chart = new JFreeChart("Test", plot);
ChartViewer viewer = new ChartViewer(chart);
viewer.addChartMouseListener(new ChartMouseListenerFX() {
#Override
public void chartMouseClicked(ChartMouseEventFX e) {
ChartEntity ce = e.getEntity();
if (ce instanceof XYItemEntity) {
XYItemEntity item = (XYItemEntity) ce;
renderer.setSeriesVisible(item.getSeriesIndex(), false);
} else if (ce instanceof LegendItemEntity) {
LegendItemEntity item = (LegendItemEntity) ce;
Comparable key = item.getSeriesKey();
renderer.setSeriesVisible(dataset.getSeriesIndex(key), false);
} else {
for (int i = 0; i < dataset.getSeriesCount(); i++) {
renderer.setSeriesVisible(i, true);
}
}
}
#Override
public void chartMouseMoved(ChartMouseEventFX e) {}
});
stage.setScene(new Scene(viewer));
stage.setTitle("JFreeChartFX");
stage.setWidth(640);
stage.setHeight(480);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}

VtkRenderWindowInteractor doesn't start and cause program freezes [java]

I recently have implemented clipping in my VTK Java program. I used BoxWidget to control what should be clipped. However, i'm having an issue with vtkRenderWindowInteractor that attached to BoxWidget. The program freezes at the renderWindowInteractor.Start() statement (I've remarked it in my code).
This is my re-simulate code :
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import vtk.*;
public class VTKWindowInteractor extends JPanel {
static {
if (!vtkNativeLibrary.LoadAllNativeLibraries()) {
for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
if (!lib.IsLoaded()) {
System.out.println(lib.GetLibraryName() + " not loaded");
}
}
System.out.println("Make sure the search path is correct: ");
System.out.println(System.getProperty("java.library.path"));
}
vtkNativeLibrary.DisableOutputWindow(null);
}
private vtkPanel renWin;
private vtkRenderWindowInteractor renderWindowInteractor;
private vtkPolyDataMapper mapper;
private vtkActor coneActor;
private vtkPlanes planes;
private vtkBoxWidget boxWidget;
public VTKWindowInteractor() {
setLayout(new BorderLayout());
renWin = new vtkPanel();
add(renWin, BorderLayout.CENTER);
renWin.setMinimumSize(new Dimension(50, 50));
renWin.GetRenderer().SetBackground(0, 0, 0); // black
renWin.GetRenderWindow().AddRenderer(renWin.GetRenderer());
}
public void render() {
mapper = new vtkPolyDataMapper();
vtkConeSource cone = new vtkConeSource();
cone.SetHeight(3.0);
cone.SetRadius(1.0);
cone.SetResolution(10);
mapper.SetInputConnection(cone.GetOutputPort());
coneActor = new vtkActor();
coneActor.SetMapper(mapper);
renWin.GetRenderer().AddActor(coneActor);
planes = new vtkPlanes();
renderWindowInteractor = new vtkRenderWindowInteractor();
renderWindowInteractor.SetRenderWindow(renWin.GetRenderWindow());
boxWidget = new vtkBoxWidget();
boxWidget.SetInteractor(renderWindowInteractor);
boxWidget.SetPlaceFactor(1.25);
boxWidget.PlaceWidget(coneActor.GetBounds());
boxWidget.AddObserver("InteractionEvent", this, "executeClipping");
renderWindowInteractor.Initialize();
boxWidget.On();
renWin.Render();
renWin.resetCamera();
/**************************************/
// This is where the freeze come from //
// //
/************************************/
renderWindowInteractor.Start(); // if i comment out this line, the program works but the boxWidget cannot be resized or rescale or moved
}
public void executeClipping() {
planes = new vtkPlanes();
boxWidget.GetPlanes(planes);
mapper.SetClippingPlanes(planes);
planes.Delete();
}
public static final int WINDOW_WIDTH = 1000;
public static final int WINDOW_HEIGHT = 500;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
VTKWindowInteractor _vtkRendererPanel = new VTKWindowInteractor();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("......");
frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
frame.setVisible(true);
frame.setLayout(new BorderLayout());
frame.add(_vtkRendererPanel);
_vtkRendererPanel.render();
}
});
}
}
I have been finding my mistake for hours and hours and frustrated hence come here to seek for help. If anyone have experienced this or know what did I do wrong please correct me. Thanks !!!
VTK version : 6.2.0
OK. I finally solved the problem. The follows is the quote from vtkPanel.java
/*
*
* Java AWT component that encapsulate vtkRenderWindow, vtkRenderer, vtkCamera,
* vtkLight.
*
* If a vtkInteractor is needed, use vtkCanvas instead. This is necessary when
* Widget and Picker are used.
*
* #author Kitware */
so I changed my
vtkPanel
to
vtkCanvas
&
renderWindowInteractor = new vtkRenderWindowInteractor();
to
renderWindowInteractor = renWin.getRenderWindowInteractor();
and it solves the problem.
Thanks and this is for anyone who are going to face similiar problem as me in the future.

Putting 3 dots at the beginning of JLabel

When the text in JLabel is too long there are visible 3 dots at the end of text. Is it possible to put them at the beginning?
You may consider using FontMetrics. class to see the length of your text under the current font.
_________________________________
|
| This is some really long text that I want to fit in the small label
|________________________________
^^^ YOUR LABEL ^^^
Say you want to fit that long text into that label.
Here is what you can do (and this is just a wild guess and I am making this on the fly)
Start with your three dots ... in a String.
Start adding appending characters to it, one by one.
Get the width of your JLabel.
Use FontMetrics to measure the length of your text , in pixels, as you append more characters
Keep adding more characters as long as the pixel length of the text is less than the width of your JLabel
Once it becomes greater than the width of the JLabel, get out of the loop.
Set this newly formed text as the text of your JLabel
You should end up like this:
_________________________________
|
| ...This is some really long tex
|________________________________
^^^ YOUR LABEL ^^^
Here is an easy way to get started with FontMetrics. Avoid the bickering there. Just do what the accepted answer says: Java: Friendlier way to get an instance of FontMetrics
SSCCE is in accordance with what the OP really wants rather than what I explained
package stack;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Toolkit;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public class BackwardsDots extends JFrame{
JLabel label = new JLabel(){
#Override
public Dimension getPreferredSize(){
return new Dimension(200,100);
}
};
String text = "This is a design requirement and not my whim";
FontMetrics fm;
Font theFontBeingUsed;
//--------------------------------------------------------------------------------
public BackwardsDots(){
getContentPane().add(label);
pack();
theFontBeingUsed = new Font("Ubuntu",Font.BOLD,14);
fm = Toolkit.getDefaultToolkit().getFontMetrics(theFontBeingUsed);
label.setText(trimmedStringCalculator(text));
label.setToolTipText(text);
label.setBorder(BorderFactory.createDashedBorder(Color.RED));
label.addComponentListener(new ComponentListener(){
#Override
public void componentHidden(ComponentEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void componentMoved(ComponentEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void componentResized(ComponentEvent arg0) {
label.setText(trimmedStringCalculator(text));
}
#Override
public void componentShown(ComponentEvent arg0) {
// TODO Auto-generated method stub
}
});
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//--------------------------------------------------------------------------------
private String trimmedStringCalculator(String inputText){
String ellipses = "...";
String textToBeDisplayed = "";
int widthOfJLabel = label.getWidth();
for(int i = text.length()-1; i >= 0; i--){
if(fm.stringWidth(ellipses + textToBeDisplayed) <= widthOfJLabel){
textToBeDisplayed = text.charAt(i) + textToBeDisplayed;
}
}
String finalText;
if(textToBeDisplayed.equals(inputText)){
finalText = inputText;
}else{
finalText = ellipses.concat(textToBeDisplayed);
}
return finalText;
}
//--------------------------------------------------------------------------------
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
#Override
public void run(){
new BackwardsDots();
}
});
}
}
Output
I have another solution, that relies on LabelUI. First the code:
LabelUI labelUI = new MetalLabelUI() {
#Override
protected String layoutCL(JLabel label, FontMetrics fontMetrics, String text, Icon icon, Rectangle viewR, Rectangle iconR, Rectangle textR) {
String clipString = "...";
// Use reversed text, because first characters may be larger or thinner than last ones.
String reversedText = new StringBuilder(text).reverse().toString();
// Let Swing do its magic.
String result = super.layoutCL(label, fontMetrics, reversedText, icon, viewR, iconR, textR);
// Not using .equals is intentional. Previous method will return a different instance
// if and only if a clip operation occurred.
if (result != text) {
// Use the same character count, but starting with the end.
result = clipString
+ text.substring(text.length() - result.length() + clipString.length());
} else {
// Restore the original
result = text;
}
return result;
}
};
The goal is to let Swing compute everything, including its clipped string, and using this as a hint to perform our own left clipping.
The trick is that we have to provide the reversed string to the super method, since our result will clip leading characters, we need to be sure that the computation was right. Characters have different widths.
The main advantage for me is that there is a very little overhead, compared to the current solution that compute a new size before the UI, and the UI will start doing the same.
EDIT: Change code to restore the original string when not clipped.
I think this is rather a system behaviour, more than JLabel's, so you couldn't really do that.

Get XY position of caret position in JTextArea

Actually, i have already ask this question in here. But, i'm making mistake. I haven't already get the solution.
First, at the question before, i can get Rectangle with
Rectangle rectangle = textArea.modelToView( textArea.getCaretPostion() );
I'm also get X and Y position.
I'm creating a editor that can add new Text Area each i press Enter key. XY position with code above always give same return in every Text Area. Look my code.
import java.awt.Container;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;
public class forquestion extends JFrame {
Container textAreaBox;
LinkedList<JTextComponent> textArea;
int nameTA;
public forquestion() {
int nameTA = 0;
textArea = new LinkedList<>();
textAreaBox = Box.createVerticalBox();
textAreaBox.add(Box.createVerticalGlue());
addLine();
this.add(textAreaBox);
this.setVisible(true);
}
public static void main(String[] args) {
forquestion app = new forquestion();
app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
public void addLine () {
JTextComponent temp_ta = createTextComponent();
textArea.add(temp_ta);
textAreaBox.add(textArea.getLast());
textAreaBox.add(Box.createVerticalGlue());
}
protected JTextComponent createTextComponent() {
JTextArea ta = new JTextArea("test");
/*if (count%2==0)
ta.setForeground(Color.red);
else
ta.setForeground(Color.GREEN);*/
ta.setFont(new Font("Courier New",Font.PLAIN,16));
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setName(Integer.toString(nameTA));
nameTA+=1;
basicKey("ENTER", enter, ta);
ta.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent ev) {
try {
taMousePressed(ev);
} catch (BadLocationException ex) {
Logger.getLogger(forquestion.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
return ta;
}
public void basicKey(String s, Action a, JTextArea ta) {
ta.getInputMap().put(KeyStroke.getKeyStroke(s), s);
ta.getActionMap().put(s, a);
}
Action enter = new AbstractAction() {
#Override
public void actionPerformed(ActionEvent e) {
addLine();
}
};
private void taMousePressed(java.awt.event.MouseEvent ev) throws BadLocationException {
int now_focus = Integer.parseInt(ev.getComponent().getName());
int _caret;
_caret = textArea.get(now_focus).getCaretPosition();
Rectangle rectangle = textArea.get(now_focus).modelToView(_caret);
double x = rectangle.getX();
//int xc = textArea.get(now_focus).getLocation().x;
double y = rectangle.getY();
//int yc = textArea.get(now_focus).getLocation().y;
//double h = rectangle.getHeight();
//double w = rectangle.getWidth();
System.out.println(x);
System.out.println(y);
//System.out.println(xc);
//System.out.println(yc);
//System.out.println(h);
//System.out.println(w);
System.out.println("");
}
}
My code will print XY position each time you press a Text Area. But, the display always same in every text area. (Try to make many Text Area and give some text) Btw, it just simple code. You need change the window frame size for update the new text area after you press enter key..hahaha.
So, my question is: How can i get the XY position of caret (text cursor) in any Text Area. I want to display JPopmenu there. :)
I hope this question clear for you. Thx before.
The Rectangle reported back is relative to the text area, where it's 0x0 position is the top, left corner of the component.
If you use something like...
popup.show(textArea.get(now_focus), rectangle.x, rectangle.y + rectangle.height);
Where popup is a JPopupMenu, it will make the required translations to the screen itself.
Now. Having said that. Personally, I would prefer to use the popup API support provided by Swing. This is going to mean needing to create a custom component that extends from JTextArea to achieve it...
public class MyPopupTextArea extends JTextArea {
/*...*/
public Point getPopupLocation(MouseEvent evt) {
Rectangle rectangle = textArea.get(now_focus).modelToView(_caret);
Point p = rectangle.getLoction();
p.y += rectangle.height;
return p;
}
}
Then, based on your needs, you can use setComponentPopup to provide a shared instance of the JPopupMenu or, if required, create a custom JPopupMenu for each instance of the custom editor and use setComponentPopup as you see fit...no messing about with mouse listeners ;)

JFreeChart auto resize on zoom

I need to plot a lot of data (150-250 points/seconds * 180secs) on a XYPlot. So if i use the autorange method, its a bit to coarse. If i zoom into the plot, i just see a range of the data (eg. 10.25 to 14.50).. its good, and it works very well, but it would be better if i see the full range, but in an better resolution.
Is there a possibility to zoom in the plot, and additionally resize the plot-area (so you have more space to print the plot), so that the full range is displayed (e.g. from 0 to 180sec) and not just a section?
What i tried so far, is to have a fixed huge plot without zooming, but it was not usable (the size was 1200x15000).
Thanks in advance!
As shown here, override getPreferredSize() to return your desired size for the ChartPanel and pack() the enclosing frame. The result obtained by applying JFrame.MAXIMIZED_BOTH in setExtendedState() will maximize use of the screen at the user's chosen resolution, but you can try a different display mode, if available.
I used the getPreferredSize() method as trashgod proposed. I extended from the org.jfree.chart.MouseWheelHandler and implemented a new handleZoomable-method as follows.
package org.jfree.chart;
import java.awt.Dimension;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.geom.Point2D;
import java.io.Serializable;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.Zoomable;
/** http://stackoverflow.com/questions/17908498/jfreechart-auto-resize-on-zoom */
class MouseWheelHandlerResize extends MouseWheelHandler {
/** The chart panel. */
private ChartPanel chartPanel;
/** The zoom factor. */
double zoomFactor;
/** minimum size */
final int MIN_SIZE = 300;
/** maximal size */
final int MAX_SIZE = 20000;
public MouseWheelHandlerResize(ChartPanel chartPanel) {
super(chartPanel);
this.chartPanel = chartPanel;
this.zoomFactor = 0.05;
}
#Override
public void mouseWheelMoved(MouseWheelEvent e) {
JFreeChart chart = this.chartPanel.getChart();
if (chart == null) {
return;
}
Plot plot = chart.getPlot();
if (plot instanceof Zoomable) {
Zoomable zoomable = (Zoomable) plot;
handleZoomable(zoomable, e);
}
else if (plot instanceof PiePlot) {
PiePlot pp = (PiePlot) plot;
pp.handleMouseWheelRotation(e.getWheelRotation());
}
}
private void handleZoomable(Zoomable zoomable, MouseWheelEvent e) {
// don't zoom unless the mouse pointer is in the plot's data area
ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
PlotRenderingInfo pinfo = info.getPlotInfo();
Point2D p = this.chartPanel.translateScreenToJava2D(e.getPoint());
if (!pinfo.getDataArea().contains(p)) {
return;
}
Plot plot = (Plot) zoomable;
// do not notify while zooming each axis
boolean notifyState = plot.isNotify();
plot.setNotify(false);
int clicks = e.getWheelRotation();
double zf = 1.0 + this.zoomFactor;
if (clicks < 0) {
zf = 1.0 / zf;
}
final Dimension dim = this.chartPanel.getPreferredSize();
this.chartPanel.setPreferredSize(new Dimension((int)(Math.min(Math.max(MIN_SIZE, dim.width)*zf, MAX_SIZE)), (int)(dim.height)));
this.chartPanel.validate();
this.chartPanel.updateUI();
plot.setNotify(notifyState); // this generates the change event too
}
}
And in the org.jfree.chart.ChartPanel Class, i just modified the setMouseWheelEnabled Method to:
public void setMouseWheelEnabled(boolean flag) {
if (flag && this.mouseWheelHandler == null) {
this.mouseWheelHandler = new MouseWheelHandlerResize(this);
}
else if (!flag && this.mouseWheelHandler != null) {
removeMouseWheelListener(this.mouseWheelHandler);
this.mouseWheelHandler = null;
}
}
And now, the CharPanel which is located in a scrollview resizes, and zooms in.

Categories

Resources