JFreeChart - always in forefront

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jfreechart175371
Posts: 8
Joined: Tue Mar 18, 2014 2:00 pm
antibot: No, of course not.

JFreeChart - always in forefront

Post by jfreechart175371 » Tue Jun 09, 2015 2:08 pm

Hello.

I would be very appreciative if someone could tell me how to change a JFreeChart so that other windows on my desktop can be in front of it. I have 20 JFreeCharts floating on my desktop and they disallow any other window from being in front of them. There must be a field or a method I can call to change this default behaviour of the JFreeChart object only I am unable to find it.

Thank you for your time.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: JFreeChart - always in forefront

Post by david.gilbert » Wed Jun 10, 2015 4:47 am

How are you displaying the charts? Normally in a Swing application you'd embed a ChartPanel somewhere in your UI which would be contained in a JFrame. There is no default behaviour that will force the frame to the front...maybe you are using a modal dialog?
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

jfreechart175371
Posts: 8
Joined: Tue Mar 18, 2014 2:00 pm
antibot: No, of course not.

Re: JFreeChart - always in forefront

Post by jfreechart175371 » Wed Jun 10, 2015 8:41 am

Below you can see the code I am employing. MY OS is Windows 7 Enterprise. There are several instances of this class which are created and displayed on my desktop.

Actually, I think I just realized what the problem is. When I run the application from my IDE (JGRASP) the graphs are always at the forefront for some reason, but when I run the application from the terminal window they can indeed be covered up with other applications.

I assume that is indeed the problem. If it is not I will revert on this thread. Thank you for your time.

Code: Select all

public class chartgui3 extends ApplicationFrame {

	// default values of structs and fields:
	private final double DEFVALUESSIE = -99.999;
	private final float DEFVALUE = -999.999f;	
	private final long DEFVALUE2 = -999999;
	private final int DEFVALUE3 = -999999;
		
	public JFreeChart ch;
	private ChartPanel cp;
	public int sec;
	public  String tkr;
	
	private TimeSeries lastY;
	private TimeSeries series0;
	
	private double maxlasty = -1000000.00f;
	private double minlasty = 1000000.00f;
	
	private double maxseries = -1000000.00f;		
	private double minseries = 1000000.00f;
	
	private NumberAxis axis;
	
	private TimeSeriesCollection ds, ds0;		// for the above 4 series
	
	private dateCalculations DC = new dateCalculations();
	
	public chartgui3(String tkr, int n) {
      // constructor
		super(tkr);
		this.tkr=tkr;
		sec = n;

		// i don't know why sec is needed in the below constructors ("name")
		lastY = new TimeSeries(sec+"", Minute.class);
		series0 = new TimeSeries(sec+"", Minute.class);
		
		ds = new TimeSeriesCollection();
		ds0 = new TimeSeriesCollection();

		ds.addSeries(lastY);
		ds.setDomainIsPointsInTime(true);
		
		ds0.addSeries(series0);
		ds0.setDomainIsPointsInTime(true);
		
	   ch = createChart();
		cp = new ChartPanel(ch);
		cp.setPreferredSize(new java.awt.Dimension(482,286));
		cp.setMouseZoomable(true,false);
		setContentPane(cp);
	}

private JFreeChart createChart() {
			
			// create chart:
			JFreeChart chart = ChartFactory.createTimeSeriesChart(
													tkr, // title
													"Time", // x-axis label
													"Last Trade", // y-axis label
													ds, // data
													false, // create legend?
													true, // generate tooltips?
													false // generate URLs?
													);
			chart.setBackgroundPaint(Color.white);
			XYPlot plot = (XYPlot) chart.getPlot();
			plot.setBackgroundPaint(Color.lightGray);	

			// ---------------------------------------- price axis (2 lines) ----------------------
			// price level high axis (red):
			ValueAxis yAxis = (NumberAxis)plot.getRangeAxis();							
			yAxis.setTickLabelPaint(Color.red);
			yAxis.setVisible(true);
			
			// first red line:
			XYItemRenderer renderer = plot.getRenderer();
         renderer.setPaint(Color.red);
						
			// --------------------------------------- price axis ------------------------

			// ---------------------------------------- signal axis (2 lines) -----------------------
			// add axis (black)  - bp premium or discount (Y/Y^):
			axis = new NumberAxis("last / implied (bp)");		
			axis.setTickLabelPaint(Color.black);		
			plot.setRangeAxis(2, axis);
			plot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_RIGHT);
			axis.setVisible(true);
			
			// first blue line (high discount):
			XYItemRenderer renderer1 = new StandardXYItemRenderer();
         renderer1.setSeriesPaint(0, Color.black);
			plot.setDataset(2, ds0);
			plot.setRenderer(2, renderer1);
			plot.mapDatasetToRangeAxis(2, 2);		
	
			// ------------------------------------------ signal axis ---------------------
			
			
			return chart;
	}

Naxter
Posts: 45
Joined: Thu Jun 26, 2014 8:24 am
antibot: No, of course not.
Location: Germany, Aachen

Re: JFreeChart - always in forefront

Post by Naxter » Fri Jun 12, 2015 7:34 am

As your Frame ist actually extending a JFrame, you can use this method : http://docs.oracle.com/javase/7/docs/ap ... boolean%29

Hope it works for you

Locked