0

I had method,which returns JPanel with JFreeChart with ChartActionListener. In my test program it works well,i just write setContentPane(createContent()); and program show it as full size JPanel.

When i create my main Frame with JPanel in a special place(i do it by NetBeans swing constructor), my JPanel could not show content, it just stays an empty JPanel.

I tried to put it like JPanel pan = createContent(); jPanel1.add(pan);= doesn't work.

I also tried to write : jPanel1 = createContent(); : it doesn't work.

It only works when i write same after....:initComponents();CrossHair cross = new CrossHair();setContentPane(cross.createContent());

So it shows content, but other parts of my programm become unreachable..here is the method createContent:

    private JPanel createContent() {
        JFreeChart chart = createChart(createDataset());
        chartPanel = new ChartPanel(chart);
        chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
             //---- to not make that code big  
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
             //---to not make that code big  
        }
    });

    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.RED, new BasicStroke(0f));
    xCrosshair.setLabelVisible(true);
    yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
    yCrosshair.setLabelVisible(true);
    crosshairOverlay.addDomainCrosshair(xCrosshair);
    crosshairOverlay.addRangeCrosshair(yCrosshair);
    chartPanel.addOverlay(crosshairOverlay);
    return chartPanel;}

Thanks in advice, any example could be helpful

pczeus
  • 7,709
  • 4
  • 36
  • 51
Sashok
  • 1
  • 2

1 Answers1

0

I didn't see the difference between ChartPanel and jPanel.

I solved this by using

jPanel1.add(cross.createContent(), BorderLayout.CENTER);
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Sashok
  • 1
  • 2